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: [] },
Nonce: { type: Number, default: 0 },
LastLoginDay: { type: Number },
LatestEventMessageDate: { type: Date, default: 0 }
LatestEventMessageDate: { type: Date, default: 0 },
isAdministrator: { type: Boolean, required: false, default: false }
},
opts
);

View File

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

View File

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