feat: store administrator status in database
Closes 907
This commit is contained in:
parent
a03c987f69
commit
2725784bc8
@ -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
|
||||||
);
|
);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user