forked from OpenWF/SpaceNinjaServer
		
	feat: daily reset for syndicate standing (#582)
This commit is contained in:
		
							parent
							
								
									8a43eae230
								
							
						
					
					
						commit
						d9c94664c3
					
				@ -1,5 +1,5 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { getAccountForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
 | 
			
		||||
import { config } from "@/src/services/configService";
 | 
			
		||||
@ -11,15 +11,15 @@ import { ExportCustoms, ExportFlavour, ExportKeys, ExportRegions, ExportResource
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
			
		||||
const inventoryController: RequestHandler = async (request, response) => {
 | 
			
		||||
    let accountId;
 | 
			
		||||
    let account;
 | 
			
		||||
    try {
 | 
			
		||||
        accountId = await getAccountIdForRequest(request);
 | 
			
		||||
        account = await getAccountForRequest(request);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        response.status(400).send("Log-in expired");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const inventory = await Inventory.findOne({ accountOwnerId: accountId })
 | 
			
		||||
    const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
 | 
			
		||||
        .populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
 | 
			
		||||
        .populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,29 @@ const inventoryController: RequestHandler = async (request, response) => {
 | 
			
		||||
        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
 | 
			
		||||
    const inventoryJSON = inventory.toJSON();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@ const loginController: RequestHandler = async (request, response) => {
 | 
			
		||||
            });
 | 
			
		||||
            logger.debug("created new account");
 | 
			
		||||
            // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
			
		||||
            const { email, password, ...databaseAccount } = newAccount;
 | 
			
		||||
            const { email, password, LastLoginDay, ...databaseAccount } = newAccount;
 | 
			
		||||
            const newLoginResponse: ILoginResponse = {
 | 
			
		||||
                ...databaseAccount,
 | 
			
		||||
                Groups: groups,
 | 
			
		||||
@ -77,7 +77,7 @@ const loginController: RequestHandler = async (request, response) => {
 | 
			
		||||
    }
 | 
			
		||||
    await account.save();
 | 
			
		||||
 | 
			
		||||
    const { email, password, ...databaseAccount } = account.toJSON();
 | 
			
		||||
    const { email, password, LastLoginDay, ...databaseAccount } = account.toJSON();
 | 
			
		||||
    const newLoginResponse: ILoginResponse = {
 | 
			
		||||
        ...databaseAccount,
 | 
			
		||||
        Groups: groups,
 | 
			
		||||
 | 
			
		||||
@ -635,6 +635,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
 | 
			
		||||
        DailyAffiliationZariman: Number,
 | 
			
		||||
        DailyAffiliationKahl: Number,
 | 
			
		||||
        DailyAffiliationCavia: Number,
 | 
			
		||||
        DailyAffiliationHex: Number,
 | 
			
		||||
 | 
			
		||||
        //Daily Focus limit
 | 
			
		||||
        DailyFocus: Number,
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,8 @@ const databaseAccountSchema = new Schema<IDatabaseAccountDocument>(
 | 
			
		||||
        AmazonRefreshToken: { type: String },
 | 
			
		||||
        ConsentNeeded: { type: Boolean, required: true },
 | 
			
		||||
        TrackedSettings: { type: [String], default: [] },
 | 
			
		||||
        Nonce: { type: Number, default: 0 }
 | 
			
		||||
        Nonce: { type: Number, default: 0 },
 | 
			
		||||
        LastLoginDay: { type: Number }
 | 
			
		||||
    },
 | 
			
		||||
    opts
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
@ -44,7 +44,7 @@ export const createPersonalRooms = async (accountId: Types.ObjectId, shipId: Typ
 | 
			
		||||
    await personalRooms.save();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
 | 
			
		||||
export const getAccountForRequest = async (req: Request) => {
 | 
			
		||||
    if (!req.query.accountId) {
 | 
			
		||||
        throw new Error("Request is missing accountId parameter");
 | 
			
		||||
    }
 | 
			
		||||
@ -61,5 +61,9 @@ export const getAccountIdForRequest = async (req: Request): Promise<string> => {
 | 
			
		||||
    if (!account) {
 | 
			
		||||
        throw new Error("Invalid accountId-nonce pair");
 | 
			
		||||
    }
 | 
			
		||||
    return account._id.toString();
 | 
			
		||||
    return account;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
 | 
			
		||||
    return (await getAccountForRequest(req))._id.toString();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -283,6 +283,7 @@ export interface IInventoryResponse {
 | 
			
		||||
    NemesisAbandonedRewards: string[];
 | 
			
		||||
    DailyAffiliationKahl: number;
 | 
			
		||||
    DailyAffiliationCavia: number;
 | 
			
		||||
    DailyAffiliationHex?: number;
 | 
			
		||||
    LastInventorySync: IOid;
 | 
			
		||||
    NextRefill: IMongoDate; // Next time argon crystals will have a decay tick
 | 
			
		||||
    FoundToday?: IMiscItem[]; // for Argon Crystals
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,7 @@ export interface IDatabaseAccount {
 | 
			
		||||
    ConsentNeeded: boolean;
 | 
			
		||||
    TrackedSettings: string[];
 | 
			
		||||
    Nonce: number;
 | 
			
		||||
    LastLoginDay?: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ILoginRequest {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user