This commit is contained in:
@ -15,7 +15,12 @@ export const admin = mysqlTable('admin', {
|
||||
|
||||
export type AddAdminReq = Omit<typeof admin.$inferInsert, 'id'>;
|
||||
|
||||
export type EditAdminReq = Omit<typeof admin.$inferInsert, 'id'> & { id: number };
|
||||
export type EditAdminReq = {
|
||||
id: number;
|
||||
username: string;
|
||||
password: string | null;
|
||||
permissions: number;
|
||||
};
|
||||
|
||||
export type GetAdminReq = {};
|
||||
export type GetAdminRes = Omit<typeof admin.$inferSelect, 'password'>[];
|
||||
@ -39,9 +44,15 @@ export async function addAdmin(db: Database, values: AddAdminReq) {
|
||||
}
|
||||
|
||||
export async function editAdmin(db: Database, values: EditAdminReq) {
|
||||
values.password = bcrypt.hashSync(values.password, 10);
|
||||
|
||||
await db.update(admin).set(values).where(eq(admin.id, values.id));
|
||||
return db
|
||||
.update(admin)
|
||||
.set({
|
||||
id: values.id,
|
||||
username: values.username,
|
||||
password: values.password != null ? bcrypt.hashSync(values.password, 10) : undefined,
|
||||
permissions: values.permissions
|
||||
})
|
||||
.where(eq(admin.id, values.id));
|
||||
}
|
||||
|
||||
export async function getAdmins(db: Database, _values: GetAdminReq): Promise<GetAdminRes> {
|
||||
|
Reference in New Issue
Block a user