forked from OpenWF/SpaceNinjaServer
		
	fix _id field in response
This commit is contained in:
		
							parent
							
								
									1109d8e0ff
								
							
						
					
					
						commit
						ea201e3be8
					
				@ -8,6 +8,7 @@ import { PersonalRooms } from "@/src/models/personalRoomsModel";
 | 
			
		||||
import { Ship } from "@/src/models/shipModel";
 | 
			
		||||
import { Stats } from "@/src/models/statsModel";
 | 
			
		||||
import { GuildMember } from "@/src/models/guildModel";
 | 
			
		||||
import { Leaderboard } from "@/src/models/leaderboardModel";
 | 
			
		||||
 | 
			
		||||
export const deleteAccountController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
@ -17,6 +18,7 @@ export const deleteAccountController: RequestHandler = async (req, res) => {
 | 
			
		||||
        GuildMember.deleteMany({ accountId: accountId }),
 | 
			
		||||
        Inbox.deleteMany({ ownerId: accountId }),
 | 
			
		||||
        Inventory.deleteOne({ accountOwnerId: accountId }),
 | 
			
		||||
        Leaderboard.deleteMany({ accountId: accountId }),
 | 
			
		||||
        Loadout.deleteOne({ loadoutOwnerId: accountId }),
 | 
			
		||||
        PersonalRooms.deleteOne({ personalRoomsOwnerId: accountId }),
 | 
			
		||||
        Ship.deleteMany({ ShipOwnerId: accountId }),
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ const leaderboardEntrySchema = new Schema<ILeaderboardEntryDatabase>(
 | 
			
		||||
    {
 | 
			
		||||
        leaderboard: { type: String, required: true },
 | 
			
		||||
        displayName: { type: String, required: true },
 | 
			
		||||
        accountId: { type: Schema.Types.ObjectId, required: true },
 | 
			
		||||
        score: { type: Number, required: true },
 | 
			
		||||
        expiry: { type: Date, required: true }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,9 @@
 | 
			
		||||
import { toOid } from "../helpers/inventoryHelpers";
 | 
			
		||||
import { Leaderboard } from "../models/leaderboardModel";
 | 
			
		||||
import { ILeaderboardEntryClient } from "../types/leaderboardTypes";
 | 
			
		||||
 | 
			
		||||
export const submitLeaderboardScore = async (
 | 
			
		||||
    leaderboard: string,
 | 
			
		||||
    accountId: string,
 | 
			
		||||
    displayName: string,
 | 
			
		||||
    score: number
 | 
			
		||||
): Promise<void> => {
 | 
			
		||||
@ -21,7 +21,7 @@ export const submitLeaderboardScore = async (
 | 
			
		||||
    }
 | 
			
		||||
    await Leaderboard.findOneAndUpdate(
 | 
			
		||||
        { leaderboard, displayName },
 | 
			
		||||
        { $max: { score }, $set: { expiry } },
 | 
			
		||||
        { $max: { score }, $set: { accountId, expiry } },
 | 
			
		||||
        { upsert: true }
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
@ -39,7 +39,7 @@ export const getLeaderboard = async (
 | 
			
		||||
    let r = before;
 | 
			
		||||
    for (const entry of entries) {
 | 
			
		||||
        res.push({
 | 
			
		||||
            _id: toOid(entry._id),
 | 
			
		||||
            _id: entry.accountId.toString(),
 | 
			
		||||
            s: entry.score,
 | 
			
		||||
            r: ++r,
 | 
			
		||||
            n: entry.displayName
 | 
			
		||||
 | 
			
		||||
@ -303,7 +303,12 @@ export const updateStats = async (accountOwnerId: string, payload: IStatsUpdate)
 | 
			
		||||
                                    playerStats.Races.set(race, { highScore });
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
                                await submitLeaderboardScore("daily.accounts." + race, payload.displayName, highScore);
 | 
			
		||||
                                await submitLeaderboardScore(
 | 
			
		||||
                                    "daily.accounts." + race,
 | 
			
		||||
                                    accountOwnerId,
 | 
			
		||||
                                    payload.displayName,
 | 
			
		||||
                                    highScore
 | 
			
		||||
                                );
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            break;
 | 
			
		||||
 | 
			
		||||
@ -1,14 +1,15 @@
 | 
			
		||||
import { IOid } from "./commonTypes";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
 | 
			
		||||
export interface ILeaderboardEntryDatabase {
 | 
			
		||||
    leaderboard: string;
 | 
			
		||||
    accountId: Types.ObjectId;
 | 
			
		||||
    displayName: string;
 | 
			
		||||
    score: number;
 | 
			
		||||
    expiry: Date;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ILeaderboardEntryClient {
 | 
			
		||||
    _id: IOid;
 | 
			
		||||
    _id: string; // player id
 | 
			
		||||
    s: number; // score
 | 
			
		||||
    r: number; // rank
 | 
			
		||||
    n: string; // displayName
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user