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