Add Inbox
This commit is contained in:
parent
0c745aa1d7
commit
d12eb67248
@ -1,7 +1,38 @@
|
||||
import { RequestHandler } from "express";
|
||||
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);
|
||||
};
|
||||
|
||||
|
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 {
|
||||
$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 */
|
||||
|
||||
import { Document, Types } from "mongoose";
|
||||
import { Oid } from "./commonTypes";
|
||||
import { ODate, Oid } from "./commonTypes";
|
||||
|
||||
export interface IInventoryDatabase extends IInventoryResponse {
|
||||
accountOwnerId: Types.ObjectId;
|
||||
@ -9,7 +9,7 @@ export interface IInventoryDatabase extends IInventoryResponse {
|
||||
|
||||
export interface IInventoryResponse {
|
||||
SubscribedToEmails: number;
|
||||
Created: Date;
|
||||
Created: ODate;
|
||||
RewardSeed: number;
|
||||
RegularCredits: number;
|
||||
PremiumCredits: number;
|
||||
@ -53,7 +53,7 @@ export interface IInventoryResponse {
|
||||
Recipes: Consumable[];
|
||||
WeaponSkins: WeaponSkin[];
|
||||
PendingRecipes: PendingRecipe[];
|
||||
TrainingDate: Date;
|
||||
TrainingDate: ODate;
|
||||
PlayerLevel: number;
|
||||
Upgrades: CrewShipSalvagedWeaponSkin[];
|
||||
EquippedGear: string[];
|
||||
@ -130,7 +130,7 @@ export interface IInventoryResponse {
|
||||
InvasionChainProgress: InvasionChainProgress[];
|
||||
DataKnives: DataKnife[];
|
||||
NemesisHistory: NemesisHistory[];
|
||||
LastNemesisAllySpawnTime: Date;
|
||||
LastNemesisAllySpawnTime: ODate;
|
||||
Settings: Settings;
|
||||
PersonalTechProjects: PersonalTechProject[];
|
||||
CrewShips: CrewShip[];
|
||||
@ -141,7 +141,7 @@ export interface IInventoryResponse {
|
||||
CrewShipWeapons: CrewShipWeapon[];
|
||||
CrewShipSalvagedWeapons: CrewShipWeapon[];
|
||||
CrewShipWeaponSkins: CrewShipSalvagedWeaponSkin[];
|
||||
TradeBannedUntil: Date;
|
||||
TradeBannedUntil: ODate;
|
||||
PlayedParkourTutorial: boolean;
|
||||
SubscribedToEmailsPersonalized: number;
|
||||
MechBin: CrewMemberBinClass;
|
||||
@ -149,7 +149,7 @@ export interface IInventoryResponse {
|
||||
DailyAffiliationNecraloid: number;
|
||||
MechSuits: MechSuit[];
|
||||
InfestedFoundry: InfestedFoundry;
|
||||
BlessingCooldown: Date;
|
||||
BlessingCooldown: ODate;
|
||||
CrewMemberBin: CrewMemberBinClass;
|
||||
CrewShipHarnesses: CrewShipHarness[];
|
||||
CrewShipRawSalvage: Consumable[];
|
||||
@ -161,7 +161,7 @@ export interface IInventoryResponse {
|
||||
NemesisAbandonedRewards: string[];
|
||||
DailyAffiliationKahl: number;
|
||||
LastInventorySync: Oid;
|
||||
NextRefill: Date;
|
||||
NextRefill: ODate;
|
||||
ActiveLandscapeTraps: any[];
|
||||
EvolutionProgress: any[];
|
||||
RepVotes: any[];
|
||||
@ -213,10 +213,6 @@ export interface Alignment {
|
||||
Alignment: number;
|
||||
}
|
||||
|
||||
export interface Date {
|
||||
$date: { $numberLong: string };
|
||||
}
|
||||
|
||||
export interface Booster {
|
||||
ExpiryDate: number;
|
||||
ItemType: string;
|
||||
@ -277,7 +273,7 @@ export interface CrewMember {
|
||||
ItemType: string;
|
||||
NemesisFingerprint: number;
|
||||
Seed: number;
|
||||
HireDate: Date;
|
||||
HireDate: ODate;
|
||||
AssignedRole: number;
|
||||
SkillEfficiency: SkillEfficiency;
|
||||
WeaponConfigIdx: number;
|
||||
@ -447,7 +443,7 @@ export interface Drone {
|
||||
ItemType: string;
|
||||
CurrentHP: number;
|
||||
ItemId: Oid;
|
||||
RepairStart?: Date;
|
||||
RepairStart?: ODate;
|
||||
}
|
||||
|
||||
export interface EmailItem {
|
||||
@ -535,7 +531,7 @@ export interface InvasionChainProgress {
|
||||
|
||||
export interface KubrowPetEgg {
|
||||
ItemType: KubrowPetEggItemType;
|
||||
ExpirationDate: Date;
|
||||
ExpirationDate: ODate;
|
||||
ItemId: Oid;
|
||||
}
|
||||
|
||||
@ -588,7 +584,7 @@ export interface KubrowPet {
|
||||
Polarized?: number;
|
||||
Polarity?: Polarity[];
|
||||
Features?: number;
|
||||
InfestationDate?: Date;
|
||||
InfestationDate?: ODate;
|
||||
InfestationDays?: number;
|
||||
InfestationType?: string;
|
||||
ItemId: Oid;
|
||||
@ -608,7 +604,7 @@ export interface Details {
|
||||
HasCollar: boolean;
|
||||
PrintsRemaining: number;
|
||||
Status: Status;
|
||||
HatchDate: Date;
|
||||
HatchDate: ODate;
|
||||
DominantTraits: Traits;
|
||||
RecessiveTraits: Traits;
|
||||
IsMale: boolean;
|
||||
@ -812,7 +808,7 @@ export interface Mission {
|
||||
Completes: number;
|
||||
Tier?: number;
|
||||
Tag: string;
|
||||
RewardsCooldownTime?: Date;
|
||||
RewardsCooldownTime?: ODate;
|
||||
}
|
||||
|
||||
export interface MoaPet {
|
||||
@ -837,7 +833,7 @@ export interface NemesisHistory {
|
||||
BirthNode: BirthNode;
|
||||
Rank: number;
|
||||
k: boolean;
|
||||
d: Date;
|
||||
d: ODate;
|
||||
GuessHistory?: number[];
|
||||
currentGuess?: number;
|
||||
Traded?: boolean;
|
||||
@ -891,13 +887,13 @@ export interface AbilityOverride {
|
||||
}
|
||||
|
||||
export interface PendingCoupon {
|
||||
Expiry: Date;
|
||||
Expiry: ODate;
|
||||
Discount: number;
|
||||
}
|
||||
|
||||
export interface PendingRecipe {
|
||||
ItemType: string;
|
||||
CompletionDate: Date;
|
||||
CompletionDate: ODate;
|
||||
ItemId: Oid;
|
||||
}
|
||||
|
||||
@ -956,7 +952,7 @@ export enum GivingSlotOrderInfo {
|
||||
}
|
||||
|
||||
export interface PeriodicMissionCompletion {
|
||||
date: Date;
|
||||
date: ODate;
|
||||
tag: string;
|
||||
count?: number;
|
||||
}
|
||||
@ -975,7 +971,7 @@ export interface PersonalTechProject {
|
||||
ReqCredits: number;
|
||||
ItemType: string;
|
||||
ReqItems: Consumable[];
|
||||
CompletionDate?: Date;
|
||||
CompletionDate?: ODate;
|
||||
ItemId: Oid;
|
||||
ProductCategory?: string;
|
||||
CategoryItemId?: Oid;
|
||||
@ -996,7 +992,7 @@ export interface QuestKey {
|
||||
unlock?: boolean;
|
||||
Completed?: boolean;
|
||||
ItemType: string;
|
||||
CompletionDate?: Date;
|
||||
CompletionDate?: ODate;
|
||||
}
|
||||
|
||||
export interface Progress {
|
||||
@ -1170,7 +1166,7 @@ export interface ISuitDatabase {
|
||||
Configs: SuitConfig[];
|
||||
UpgradeVer?: number;
|
||||
XP?: number;
|
||||
InfestationDate?: Date;
|
||||
InfestationDate?: ODate;
|
||||
Features?: number;
|
||||
Polarity?: Polarity[];
|
||||
Polarized?: number;
|
||||
@ -1215,15 +1211,15 @@ export interface WebFlags {
|
||||
activeBuyPlat: number;
|
||||
noShow2FA: boolean;
|
||||
Tennocon2018Digital: boolean;
|
||||
VisitPrimeAccess: Date;
|
||||
VisitTennocon2019: Date;
|
||||
enteredSC2019: Date;
|
||||
VisitPrimeVault: Date;
|
||||
VisitBuyPlatinum: Date;
|
||||
ClickedSku_640_Page__en_buyplatinum: Date;
|
||||
ClickedSku_640_Page__buyplatinum: Date;
|
||||
VisitStarterPack: Date;
|
||||
VisitPrimeAccess: ODate;
|
||||
VisitTennocon2019: ODate;
|
||||
enteredSC2019: ODate;
|
||||
VisitPrimeVault: ODate;
|
||||
VisitBuyPlatinum: ODate;
|
||||
ClickedSku_640_Page__en_buyplatinum: ODate;
|
||||
ClickedSku_640_Page__buyplatinum: ODate;
|
||||
VisitStarterPack: ODate;
|
||||
Tennocon2020Digital: boolean;
|
||||
Anniversary2021: boolean;
|
||||
HitDownloadBtn: Date;
|
||||
HitDownloadBtn: ODate;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user