feat: updateSongChallenge (#1024)
Closes #707 untested but should be correct based on all the information I could find Reviewed-on: OpenWF/SpaceNinjaServer#1024
This commit is contained in:
parent
da2b50d537
commit
bbc40d5534
50
src/controllers/api/updateSongChallengeController.ts
Normal file
50
src/controllers/api/updateSongChallengeController.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import { addShipDecorations, getInventory } from "@/src/services/inventoryService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const updateSongChallengeController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId);
|
||||
const request = getJSONfromString<IUpdateSongChallengeRequest>(String(req.body));
|
||||
inventory.SongChallenges ??= [];
|
||||
let songChallenge = inventory.SongChallenges.find(x => x.Song == request.Song);
|
||||
if (!songChallenge) {
|
||||
songChallenge =
|
||||
inventory.SongChallenges[inventory.SongChallenges.push({ Song: request.Song, Difficulties: [] }) - 1];
|
||||
}
|
||||
songChallenge.Difficulties.push(request.Difficulty);
|
||||
|
||||
const response: IUpdateSongChallengeResponse = {
|
||||
Song: request.Song,
|
||||
Difficulty: request.Difficulty
|
||||
};
|
||||
|
||||
// Handle all songs being completed on all difficulties
|
||||
if (inventory.SongChallenges.length == 12 && !inventory.SongChallenges.find(x => x.Difficulties.length != 2)) {
|
||||
response.Reward = "/Lotus/StoreItems/Types/Items/ShipDecos/LisetPropShawzinDuviri";
|
||||
const shipDecorationChanges = [
|
||||
{ ItemType: "/Lotus/Types/Items/ShipDecos/LisetPropShawzinDuviri", ItemCount: 1 }
|
||||
];
|
||||
response.InventoryChanges = {
|
||||
ShipDecorations: shipDecorationChanges
|
||||
};
|
||||
addShipDecorations(inventory, shipDecorationChanges);
|
||||
}
|
||||
|
||||
await inventory.save();
|
||||
res.json(response);
|
||||
};
|
||||
|
||||
interface IUpdateSongChallengeRequest {
|
||||
Song: string;
|
||||
Difficulty: number;
|
||||
}
|
||||
|
||||
interface IUpdateSongChallengeResponse {
|
||||
Song: string;
|
||||
Difficulty: number;
|
||||
Reward?: string;
|
||||
InventoryChanges?: IInventoryChanges;
|
||||
}
|
@ -73,7 +73,8 @@ import {
|
||||
IDroneClient,
|
||||
IAlignment,
|
||||
ICollectibleEntry,
|
||||
IIncentiveState
|
||||
IIncentiveState,
|
||||
ISongChallenge
|
||||
} from "../../types/inventoryTypes/inventoryTypes";
|
||||
import { IOid } from "../../types/commonTypes";
|
||||
import {
|
||||
@ -965,6 +966,14 @@ const collectibleEntrySchema = new Schema<ICollectibleEntry>(
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const songChallengeSchema = new Schema<ISongChallenge>(
|
||||
{
|
||||
Song: String,
|
||||
Difficulties: [Number]
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const pendingCouponSchema = new Schema<IPendingCouponDatabase>(
|
||||
{
|
||||
Expiry: { type: Date, default: new Date(0) },
|
||||
@ -1323,7 +1332,9 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
|
||||
EndlessXP: { type: [endlessXpProgressSchema], default: undefined },
|
||||
|
||||
DialogueHistory: dialogueHistorySchema,
|
||||
CalendarProgress: calenderProgressSchema
|
||||
CalendarProgress: calenderProgressSchema,
|
||||
|
||||
SongChallenges: { type: [songChallengeSchema], default: undefined }
|
||||
},
|
||||
{ timestamps: { createdAt: "Created", updatedAt: false } }
|
||||
);
|
||||
|
@ -92,6 +92,7 @@ import { updateAlignmentController } from "@/src/controllers/api/updateAlignment
|
||||
import { updateChallengeProgressController } from "@/src/controllers/api/updateChallengeProgressController";
|
||||
import { updateQuestController } from "@/src/controllers/api/updateQuestController";
|
||||
import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController";
|
||||
import { updateSongChallengeController } from "@/src/controllers/api/updateSongChallengeController";
|
||||
import { updateThemeController } from "@/src/controllers/api/updateThemeController";
|
||||
import { upgradesController } from "@/src/controllers/api/upgradesController";
|
||||
|
||||
@ -196,6 +197,7 @@ apiRouter.post("/updateChallengeProgress.php", updateChallengeProgressController
|
||||
apiRouter.post("/updateNodeIntros.php", genericUpdateController);
|
||||
apiRouter.post("/updateQuest.php", updateQuestController);
|
||||
apiRouter.post("/updateSession.php", updateSessionPostController);
|
||||
apiRouter.post("/updateSongChallenge.php", updateSongChallengeController);
|
||||
apiRouter.post("/updateTheme.php", updateThemeController);
|
||||
apiRouter.post("/upgrades.php", upgradesController);
|
||||
|
||||
|
@ -325,6 +325,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
|
||||
EndlessXP?: IEndlessXpProgress[];
|
||||
DialogueHistory?: IDialogueHistoryClient;
|
||||
CalendarProgress: ICalendarProgress;
|
||||
SongChallenges?: ISongChallenge[];
|
||||
}
|
||||
|
||||
export interface IAffiliation {
|
||||
@ -1079,3 +1080,8 @@ export interface ICalendarProgress {
|
||||
YearProgress: { Upgrades: unknown[] };
|
||||
SeasonProgress: ISeasonProgress;
|
||||
}
|
||||
|
||||
export interface ISongChallenge {
|
||||
Song: string;
|
||||
Difficulties: number[];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user