feat: store administrator status in database
All checks were successful
Build / build (20) (pull_request) Successful in 37s
Build / build (22) (pull_request) Successful in 1m2s
Build / build (18) (pull_request) Successful in 1m37s

Closes 907
This commit is contained in:
AMelonInsideLemon 2025-02-09 19:34:23 +01:00
parent a03c987f69
commit 2725784bc8
3 changed files with 11 additions and 2 deletions

View File

@ -21,7 +21,8 @@ const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
TrackedSettings: { type: [String], default: [] }, TrackedSettings: { type: [String], default: [] },
Nonce: { type: Number, default: 0 }, Nonce: { type: Number, default: 0 },
LastLoginDay: { type: Number }, LastLoginDay: { type: Number },
LatestEventMessageDate: { type: Date, default: 0 } LatestEventMessageDate: { type: Date, default: 0 },
isAdministrator: { type: Boolean, required: false, default: false }
}, },
opts opts
); );

View File

@ -18,7 +18,11 @@ export const isNameTaken = async (name: string): Promise<boolean> => {
}; };
export const createAccount = async (accountData: IDatabaseAccount): Promise<IDatabaseAccountJson> => { export const createAccount = async (accountData: IDatabaseAccount): Promise<IDatabaseAccountJson> => {
const account = new Account(accountData); const account = new Account({
...accountData,
isAdministrator: !(await Account.exists({}))
});
try { try {
await account.save(); await account.save();
const loadoutId = await createLoadout(account._id); const loadoutId = await createLoadout(account._id);
@ -101,6 +105,9 @@ export const getAccountIdForRequest = async (req: Request): Promise<string> => {
}; };
export const isAdministrator = (account: TAccountDocument): boolean => { export const isAdministrator = (account: TAccountDocument): boolean => {
if (account.isAdministrator) {
return true;
}
if (!config.administratorNames) { if (!config.administratorNames) {
return false; return false;
} }

View File

@ -16,6 +16,7 @@ export interface IDatabaseAccount extends IAccountAndLoginResponseCommons {
password: string; password: string;
LastLoginDay?: number; LastLoginDay?: number;
LatestEventMessageDate: Date; LatestEventMessageDate: Date;
isAdministrator?: boolean;
} }
// Includes virtual ID // Includes virtual ID