WIP: feat: store administrator status in database #936

Closed
AMelonInsideLemon wants to merge 1 commits from AMelonInsideLemon:administrator-status into main
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({
Review

provide an optional parameter, isAdministrator: false,
use that instead of querying the database instead.
For the reasons that sainan mentioned, plus avoiding unnecessary performance overhead by querying.

provide an optional parameter, isAdministrator: false, use that instead of querying the database instead. For the reasons that sainan mentioned, plus avoiding unnecessary performance overhead by querying.
...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