Add Inbox
This commit is contained in:
parent
0c745aa1d7
commit
d12eb67248
@ -1,7 +1,38 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import inbox from "@/static/fixed_responses/inbox.json";
|
import inbox from "@/static/fixed_responses/inbox.json";
|
||||||
|
import { Inbox } from "@/src/models/inboxModel";
|
||||||
|
import { DeleteInbox, UpdateInbox } from "@/src/services/inboxService";
|
||||||
|
import { parseString } from "@/src/helpers/general";
|
||||||
|
|
||||||
const inboxController: RequestHandler = (_req, res) => {
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
const inboxController: RequestHandler = async (req, res) => {
|
||||||
|
const accountId = req.query["accountId"];
|
||||||
|
const deleteId = req.query["deleteId"];
|
||||||
|
const messageId = req.query["messageId"];
|
||||||
|
const lastMessage = req.query["lastMessage"];
|
||||||
|
|
||||||
|
if (!deleteId && !messageId && !lastMessage) {
|
||||||
|
const inbox = await Inbox.find({ OwnerId: accountId });
|
||||||
|
if (!inbox) {
|
||||||
|
res.status(400).json({ error: "inbox was undefined" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.json({ Inbox: inbox });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (deleteId && !messageId && !lastMessage) {
|
||||||
|
const newInbox = await DeleteInbox(parseString(accountId), parseString(messageId));
|
||||||
|
res.json({ Inbox: newInbox });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!deleteId && messageId && !lastMessage) {
|
||||||
|
const newInbox = await UpdateInbox(parseString(accountId), parseString(messageId));
|
||||||
|
res.json({ Inbox: newInbox });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!deleteId && !messageId && lastMessage) {
|
||||||
|
console.log(lastMessage);
|
||||||
|
}
|
||||||
res.json(inbox);
|
res.json(inbox);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
43
src/models/inboxModel.ts
Normal file
43
src/models/inboxModel.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { model, Schema } from "mongoose";
|
||||||
|
import { IInboxDocument } from "../types/inboxTypes";
|
||||||
|
import { ODate, Oid } from "../types/commonTypes";
|
||||||
|
|
||||||
|
const databaseInboxSchema = new Schema<IInboxDocument>({
|
||||||
|
OwnerId: String,
|
||||||
|
globaUpgradeId: String,
|
||||||
|
sndr: String,
|
||||||
|
sub: String,
|
||||||
|
msg: String,
|
||||||
|
att: [String],
|
||||||
|
icon: String,
|
||||||
|
url: String,
|
||||||
|
highPriority: Boolean,
|
||||||
|
lowPrioNewPlayers: Boolean,
|
||||||
|
CrossPlatform: Boolean,
|
||||||
|
date: Number,
|
||||||
|
startDate: Number,
|
||||||
|
endDate: Number,
|
||||||
|
r: Boolean
|
||||||
|
});
|
||||||
|
|
||||||
|
databaseInboxSchema.set("toJSON", {
|
||||||
|
transform(_document, returnedObject) {
|
||||||
|
returnedObject.messageId = _document._id.toString();
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||||
|
returnedObject._id = { $oid: returnedObject._id.toString() } satisfies Oid;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||||
|
returnedObject.date = { $date: { $numberLong: returnedObject.date.toString() } } satisfies ODate;
|
||||||
|
if (returnedObject.startDate)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||||
|
returnedObject.startDate = { $date: { $numberLong: returnedObject.startDate.toString() } } satisfies ODate;
|
||||||
|
if (returnedObject.endDate)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||||
|
returnedObject.endDate = { $date: { $numberLong: returnedObject.endDate.toString() } } satisfies ODate;
|
||||||
|
delete returnedObject.OwnerId;
|
||||||
|
delete returnedObject.__v;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const Inbox = model<IInboxDocument>("Inbox", databaseInboxSchema);
|
||||||
|
|
||||||
|
export { Inbox };
|
17
src/services/inboxService.ts
Normal file
17
src/services/inboxService.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Inbox } from "../models/inboxModel";
|
||||||
|
|
||||||
|
const UpdateInbox = async (accountId: string, messageId: string) => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
|
const inbox = await Inbox.findOne({ _id: messageId });
|
||||||
|
if (inbox) inbox.r = true;
|
||||||
|
if (inbox) await inbox.updateOne(inbox);
|
||||||
|
return await Inbox.find({ OwnerId: accountId });
|
||||||
|
};
|
||||||
|
|
||||||
|
const DeleteInbox = async (accountId: string, messageId: string) => {
|
||||||
|
const inbox = await Inbox.findOne({ _id: messageId });
|
||||||
|
if (inbox) await inbox.deleteOne();
|
||||||
|
return await Inbox.find({ OwnerId: accountId });
|
||||||
|
};
|
||||||
|
|
||||||
|
export { UpdateInbox, DeleteInbox };
|
@ -1,3 +1,7 @@
|
|||||||
export interface Oid {
|
export interface Oid {
|
||||||
$oid: string;
|
$oid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ODate {
|
||||||
|
$date: { $numberLong: string };
|
||||||
|
}
|
||||||
|
28
src/types/inboxTypes.ts
Normal file
28
src/types/inboxTypes.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { Document } from "mongoose";
|
||||||
|
import { Oid } from "./commonTypes";
|
||||||
|
|
||||||
|
export interface IInboxDocument extends IInboxDatabase, Document {
|
||||||
|
Id: Oid;
|
||||||
|
MessageId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IInboxDatabase extends IInboxResponse {
|
||||||
|
OwnerId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IInboxResponse {
|
||||||
|
globaUpgradeId?: Oid;
|
||||||
|
sndr: string;
|
||||||
|
sub: string;
|
||||||
|
msg: string;
|
||||||
|
att?: string[];
|
||||||
|
icon: string;
|
||||||
|
url?: string;
|
||||||
|
highPriority: boolean;
|
||||||
|
lowPrioNewPlayers?: boolean;
|
||||||
|
CrossPlatform?: boolean;
|
||||||
|
date: number;
|
||||||
|
startDate?: number;
|
||||||
|
endDate?: number;
|
||||||
|
r?: boolean;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import { Document, Types } from "mongoose";
|
import { Document, Types } from "mongoose";
|
||||||
import { Oid } from "./commonTypes";
|
import { ODate, Oid } from "./commonTypes";
|
||||||
|
|
||||||
export interface IInventoryDatabase extends IInventoryResponse {
|
export interface IInventoryDatabase extends IInventoryResponse {
|
||||||
accountOwnerId: Types.ObjectId;
|
accountOwnerId: Types.ObjectId;
|
||||||
@ -9,7 +9,7 @@ export interface IInventoryDatabase extends IInventoryResponse {
|
|||||||
|
|
||||||
export interface IInventoryResponse {
|
export interface IInventoryResponse {
|
||||||
SubscribedToEmails: number;
|
SubscribedToEmails: number;
|
||||||
Created: Date;
|
Created: ODate;
|
||||||
RewardSeed: number;
|
RewardSeed: number;
|
||||||
RegularCredits: number;
|
RegularCredits: number;
|
||||||
PremiumCredits: number;
|
PremiumCredits: number;
|
||||||
@ -53,7 +53,7 @@ export interface IInventoryResponse {
|
|||||||
Recipes: Consumable[];
|
Recipes: Consumable[];
|
||||||
WeaponSkins: WeaponSkin[];
|
WeaponSkins: WeaponSkin[];
|
||||||
PendingRecipes: PendingRecipe[];
|
PendingRecipes: PendingRecipe[];
|
||||||
TrainingDate: Date;
|
TrainingDate: ODate;
|
||||||
PlayerLevel: number;
|
PlayerLevel: number;
|
||||||
Upgrades: CrewShipSalvagedWeaponSkin[];
|
Upgrades: CrewShipSalvagedWeaponSkin[];
|
||||||
EquippedGear: string[];
|
EquippedGear: string[];
|
||||||
@ -130,7 +130,7 @@ export interface IInventoryResponse {
|
|||||||
InvasionChainProgress: InvasionChainProgress[];
|
InvasionChainProgress: InvasionChainProgress[];
|
||||||
DataKnives: DataKnife[];
|
DataKnives: DataKnife[];
|
||||||
NemesisHistory: NemesisHistory[];
|
NemesisHistory: NemesisHistory[];
|
||||||
LastNemesisAllySpawnTime: Date;
|
LastNemesisAllySpawnTime: ODate;
|
||||||
Settings: Settings;
|
Settings: Settings;
|
||||||
PersonalTechProjects: PersonalTechProject[];
|
PersonalTechProjects: PersonalTechProject[];
|
||||||
CrewShips: CrewShip[];
|
CrewShips: CrewShip[];
|
||||||
@ -141,7 +141,7 @@ export interface IInventoryResponse {
|
|||||||
CrewShipWeapons: CrewShipWeapon[];
|
CrewShipWeapons: CrewShipWeapon[];
|
||||||
CrewShipSalvagedWeapons: CrewShipWeapon[];
|
CrewShipSalvagedWeapons: CrewShipWeapon[];
|
||||||
CrewShipWeaponSkins: CrewShipSalvagedWeaponSkin[];
|
CrewShipWeaponSkins: CrewShipSalvagedWeaponSkin[];
|
||||||
TradeBannedUntil: Date;
|
TradeBannedUntil: ODate;
|
||||||
PlayedParkourTutorial: boolean;
|
PlayedParkourTutorial: boolean;
|
||||||
SubscribedToEmailsPersonalized: number;
|
SubscribedToEmailsPersonalized: number;
|
||||||
MechBin: CrewMemberBinClass;
|
MechBin: CrewMemberBinClass;
|
||||||
@ -149,7 +149,7 @@ export interface IInventoryResponse {
|
|||||||
DailyAffiliationNecraloid: number;
|
DailyAffiliationNecraloid: number;
|
||||||
MechSuits: MechSuit[];
|
MechSuits: MechSuit[];
|
||||||
InfestedFoundry: InfestedFoundry;
|
InfestedFoundry: InfestedFoundry;
|
||||||
BlessingCooldown: Date;
|
BlessingCooldown: ODate;
|
||||||
CrewMemberBin: CrewMemberBinClass;
|
CrewMemberBin: CrewMemberBinClass;
|
||||||
CrewShipHarnesses: CrewShipHarness[];
|
CrewShipHarnesses: CrewShipHarness[];
|
||||||
CrewShipRawSalvage: Consumable[];
|
CrewShipRawSalvage: Consumable[];
|
||||||
@ -161,7 +161,7 @@ export interface IInventoryResponse {
|
|||||||
NemesisAbandonedRewards: string[];
|
NemesisAbandonedRewards: string[];
|
||||||
DailyAffiliationKahl: number;
|
DailyAffiliationKahl: number;
|
||||||
LastInventorySync: Oid;
|
LastInventorySync: Oid;
|
||||||
NextRefill: Date;
|
NextRefill: ODate;
|
||||||
ActiveLandscapeTraps: any[];
|
ActiveLandscapeTraps: any[];
|
||||||
EvolutionProgress: any[];
|
EvolutionProgress: any[];
|
||||||
RepVotes: any[];
|
RepVotes: any[];
|
||||||
@ -213,10 +213,6 @@ export interface Alignment {
|
|||||||
Alignment: number;
|
Alignment: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Date {
|
|
||||||
$date: { $numberLong: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Booster {
|
export interface Booster {
|
||||||
ExpiryDate: number;
|
ExpiryDate: number;
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
@ -277,7 +273,7 @@ export interface CrewMember {
|
|||||||
ItemType: string;
|
ItemType: string;
|
||||||
NemesisFingerprint: number;
|
NemesisFingerprint: number;
|
||||||
Seed: number;
|
Seed: number;
|
||||||
HireDate: Date;
|
HireDate: ODate;
|
||||||
AssignedRole: number;
|
AssignedRole: number;
|
||||||
SkillEfficiency: SkillEfficiency;
|
SkillEfficiency: SkillEfficiency;
|
||||||
WeaponConfigIdx: number;
|
WeaponConfigIdx: number;
|
||||||
@ -447,7 +443,7 @@ export interface Drone {
|
|||||||
ItemType: string;
|
ItemType: string;
|
||||||
CurrentHP: number;
|
CurrentHP: number;
|
||||||
ItemId: Oid;
|
ItemId: Oid;
|
||||||
RepairStart?: Date;
|
RepairStart?: ODate;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EmailItem {
|
export interface EmailItem {
|
||||||
@ -535,7 +531,7 @@ export interface InvasionChainProgress {
|
|||||||
|
|
||||||
export interface KubrowPetEgg {
|
export interface KubrowPetEgg {
|
||||||
ItemType: KubrowPetEggItemType;
|
ItemType: KubrowPetEggItemType;
|
||||||
ExpirationDate: Date;
|
ExpirationDate: ODate;
|
||||||
ItemId: Oid;
|
ItemId: Oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,7 +584,7 @@ export interface KubrowPet {
|
|||||||
Polarized?: number;
|
Polarized?: number;
|
||||||
Polarity?: Polarity[];
|
Polarity?: Polarity[];
|
||||||
Features?: number;
|
Features?: number;
|
||||||
InfestationDate?: Date;
|
InfestationDate?: ODate;
|
||||||
InfestationDays?: number;
|
InfestationDays?: number;
|
||||||
InfestationType?: string;
|
InfestationType?: string;
|
||||||
ItemId: Oid;
|
ItemId: Oid;
|
||||||
@ -608,7 +604,7 @@ export interface Details {
|
|||||||
HasCollar: boolean;
|
HasCollar: boolean;
|
||||||
PrintsRemaining: number;
|
PrintsRemaining: number;
|
||||||
Status: Status;
|
Status: Status;
|
||||||
HatchDate: Date;
|
HatchDate: ODate;
|
||||||
DominantTraits: Traits;
|
DominantTraits: Traits;
|
||||||
RecessiveTraits: Traits;
|
RecessiveTraits: Traits;
|
||||||
IsMale: boolean;
|
IsMale: boolean;
|
||||||
@ -812,7 +808,7 @@ export interface Mission {
|
|||||||
Completes: number;
|
Completes: number;
|
||||||
Tier?: number;
|
Tier?: number;
|
||||||
Tag: string;
|
Tag: string;
|
||||||
RewardsCooldownTime?: Date;
|
RewardsCooldownTime?: ODate;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MoaPet {
|
export interface MoaPet {
|
||||||
@ -837,7 +833,7 @@ export interface NemesisHistory {
|
|||||||
BirthNode: BirthNode;
|
BirthNode: BirthNode;
|
||||||
Rank: number;
|
Rank: number;
|
||||||
k: boolean;
|
k: boolean;
|
||||||
d: Date;
|
d: ODate;
|
||||||
GuessHistory?: number[];
|
GuessHistory?: number[];
|
||||||
currentGuess?: number;
|
currentGuess?: number;
|
||||||
Traded?: boolean;
|
Traded?: boolean;
|
||||||
@ -891,13 +887,13 @@ export interface AbilityOverride {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PendingCoupon {
|
export interface PendingCoupon {
|
||||||
Expiry: Date;
|
Expiry: ODate;
|
||||||
Discount: number;
|
Discount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PendingRecipe {
|
export interface PendingRecipe {
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
CompletionDate: Date;
|
CompletionDate: ODate;
|
||||||
ItemId: Oid;
|
ItemId: Oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -956,7 +952,7 @@ export enum GivingSlotOrderInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface PeriodicMissionCompletion {
|
export interface PeriodicMissionCompletion {
|
||||||
date: Date;
|
date: ODate;
|
||||||
tag: string;
|
tag: string;
|
||||||
count?: number;
|
count?: number;
|
||||||
}
|
}
|
||||||
@ -975,7 +971,7 @@ export interface PersonalTechProject {
|
|||||||
ReqCredits: number;
|
ReqCredits: number;
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
ReqItems: Consumable[];
|
ReqItems: Consumable[];
|
||||||
CompletionDate?: Date;
|
CompletionDate?: ODate;
|
||||||
ItemId: Oid;
|
ItemId: Oid;
|
||||||
ProductCategory?: string;
|
ProductCategory?: string;
|
||||||
CategoryItemId?: Oid;
|
CategoryItemId?: Oid;
|
||||||
@ -996,7 +992,7 @@ export interface QuestKey {
|
|||||||
unlock?: boolean;
|
unlock?: boolean;
|
||||||
Completed?: boolean;
|
Completed?: boolean;
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
CompletionDate?: Date;
|
CompletionDate?: ODate;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Progress {
|
export interface Progress {
|
||||||
@ -1170,7 +1166,7 @@ export interface ISuitDatabase {
|
|||||||
Configs: SuitConfig[];
|
Configs: SuitConfig[];
|
||||||
UpgradeVer?: number;
|
UpgradeVer?: number;
|
||||||
XP?: number;
|
XP?: number;
|
||||||
InfestationDate?: Date;
|
InfestationDate?: ODate;
|
||||||
Features?: number;
|
Features?: number;
|
||||||
Polarity?: Polarity[];
|
Polarity?: Polarity[];
|
||||||
Polarized?: number;
|
Polarized?: number;
|
||||||
@ -1215,15 +1211,15 @@ export interface WebFlags {
|
|||||||
activeBuyPlat: number;
|
activeBuyPlat: number;
|
||||||
noShow2FA: boolean;
|
noShow2FA: boolean;
|
||||||
Tennocon2018Digital: boolean;
|
Tennocon2018Digital: boolean;
|
||||||
VisitPrimeAccess: Date;
|
VisitPrimeAccess: ODate;
|
||||||
VisitTennocon2019: Date;
|
VisitTennocon2019: ODate;
|
||||||
enteredSC2019: Date;
|
enteredSC2019: ODate;
|
||||||
VisitPrimeVault: Date;
|
VisitPrimeVault: ODate;
|
||||||
VisitBuyPlatinum: Date;
|
VisitBuyPlatinum: ODate;
|
||||||
ClickedSku_640_Page__en_buyplatinum: Date;
|
ClickedSku_640_Page__en_buyplatinum: ODate;
|
||||||
ClickedSku_640_Page__buyplatinum: Date;
|
ClickedSku_640_Page__buyplatinum: ODate;
|
||||||
VisitStarterPack: Date;
|
VisitStarterPack: ODate;
|
||||||
Tennocon2020Digital: boolean;
|
Tennocon2020Digital: boolean;
|
||||||
Anniversary2021: boolean;
|
Anniversary2021: boolean;
|
||||||
HitDownloadBtn: Date;
|
HitDownloadBtn: ODate;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user