feat: implement daily reset for syndicate standing
This commit is contained in:
		
							parent
							
								
									596aea7890
								
							
						
					
					
						commit
						17f511359c
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
 | 
					import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
 | 
				
			||||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
					import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { config } from "@/src/services/configService";
 | 
					import { config } from "@/src/services/configService";
 | 
				
			||||||
@ -12,15 +12,15 @@ import { ExportCustoms, ExportFlavour, ExportKeys, ExportResources } from "warfr
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
					// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
				
			||||||
const inventoryController: RequestHandler = async (request, response) => {
 | 
					const inventoryController: RequestHandler = async (request, response) => {
 | 
				
			||||||
    let accountId;
 | 
					    let account;
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        accountId = await getAccountIdForRequest(request);
 | 
					        account = await getAccountForRequest(request);
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
        response.status(400).send("Log-in expired");
 | 
					        response.status(400).send("Log-in expired");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const inventory = await Inventory.findOne({ accountOwnerId: accountId })
 | 
					    const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
 | 
				
			||||||
        .populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
 | 
					        .populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
 | 
				
			||||||
        .populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
 | 
					        .populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -29,6 +29,29 @@ const inventoryController: RequestHandler = async (request, response) => {
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Handle daily reset
 | 
				
			||||||
 | 
					    const today: number = Math.trunc(new Date().getTime() / 86400000);
 | 
				
			||||||
 | 
					    if (account.LastLoginDay != today) {
 | 
				
			||||||
 | 
					        account.LastLoginDay = today;
 | 
				
			||||||
 | 
					        await account.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inventory.DailyAffiliation = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationPvp = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationLibrary = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationCetus = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationQuills = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationSolaris = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationVentkids = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationVox = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationEntrati = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationNecraloid = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationZariman = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationKahl = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationCavia = 16000;
 | 
				
			||||||
 | 
					        inventory.DailyAffiliationHex = 16000;
 | 
				
			||||||
 | 
					        await inventory.save();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //TODO: make a function that converts from database representation to client
 | 
					    //TODO: make a function that converts from database representation to client
 | 
				
			||||||
    const inventoryJSON = inventory.toJSON();
 | 
					    const inventoryJSON = inventory.toJSON();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -635,6 +635,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
 | 
				
			|||||||
        DailyAffiliationZariman: Number,
 | 
					        DailyAffiliationZariman: Number,
 | 
				
			||||||
        DailyAffiliationKahl: Number,
 | 
					        DailyAffiliationKahl: Number,
 | 
				
			||||||
        DailyAffiliationCavia: Number,
 | 
					        DailyAffiliationCavia: Number,
 | 
				
			||||||
 | 
					        DailyAffiliationHex: Number,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Daily Focus limit
 | 
					        //Daily Focus limit
 | 
				
			||||||
        DailyFocus: Number,
 | 
					        DailyFocus: Number,
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,8 @@ const databaseAccountSchema = new Schema<IDatabaseAccountDocument>(
 | 
				
			|||||||
        AmazonRefreshToken: { type: String },
 | 
					        AmazonRefreshToken: { type: String },
 | 
				
			||||||
        ConsentNeeded: { type: Boolean, required: true },
 | 
					        ConsentNeeded: { type: Boolean, required: true },
 | 
				
			||||||
        TrackedSettings: { type: [String], default: [] },
 | 
					        TrackedSettings: { type: [String], default: [] },
 | 
				
			||||||
        Nonce: { type: Number, default: 0 }
 | 
					        Nonce: { type: Number, default: 0 },
 | 
				
			||||||
 | 
					        LastLoginDay: { type: Number }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    opts
 | 
					    opts
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
				
			|||||||
@ -275,6 +275,7 @@ export interface IInventoryResponse {
 | 
				
			|||||||
    NemesisAbandonedRewards: string[];
 | 
					    NemesisAbandonedRewards: string[];
 | 
				
			||||||
    DailyAffiliationKahl: number;
 | 
					    DailyAffiliationKahl: number;
 | 
				
			||||||
    DailyAffiliationCavia: number;
 | 
					    DailyAffiliationCavia: number;
 | 
				
			||||||
 | 
					    DailyAffiliationHex?: number;
 | 
				
			||||||
    LastInventorySync: IOid;
 | 
					    LastInventorySync: IOid;
 | 
				
			||||||
    NextRefill: IMongoDate; // Next time argon crystals will have a decay tick
 | 
					    NextRefill: IMongoDate; // Next time argon crystals will have a decay tick
 | 
				
			||||||
    FoundToday?: IMiscItem[]; // for Argon Crystals
 | 
					    FoundToday?: IMiscItem[]; // for Argon Crystals
 | 
				
			||||||
 | 
				
			|||||||
@ -32,6 +32,7 @@ export interface IDatabaseAccount {
 | 
				
			|||||||
    ConsentNeeded: boolean;
 | 
					    ConsentNeeded: boolean;
 | 
				
			||||||
    TrackedSettings: string[];
 | 
					    TrackedSettings: string[];
 | 
				
			||||||
    Nonce: number;
 | 
					    Nonce: number;
 | 
				
			||||||
 | 
					    LastLoginDay?: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ILoginRequest {
 | 
					export interface ILoginRequest {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user