From ec3e58d1b2cf73de501f21b30f37625c695e704c Mon Sep 17 00:00:00 2001 From: rubikscraft Date: Sat, 3 Sep 2022 21:08:28 +0200 Subject: [PATCH] Fix bug in deletionkeys --- backend/src/collections/image-db/image-db.service.ts | 9 ++++++--- backend/src/collections/role-db/role-db.service.ts | 5 ++++- backend/src/collections/user-db/user-db.service.ts | 1 + backend/src/database/entities/image.entity.ts | 5 +---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/src/collections/image-db/image-db.service.ts b/backend/src/collections/image-db/image-db.service.ts index 0cc968e..b27a4b0 100644 --- a/backend/src/collections/image-db/image-db.service.ts +++ b/backend/src/collections/image-db/image-db.service.ts @@ -33,12 +33,15 @@ export class ImageDBService { if (withDeleteKey) imageEntity.delete_key = generateRandomString(32); try { - imageEntity = await this.imageRepo.save(imageEntity, { reload: true }); + imageEntity = await this.imageRepo.save(imageEntity, { + reload: true, + }); + + if (imageEntity.delete_key === null) delete imageEntity.delete_key; + return imageEntity; } catch (e) { return Fail(FT.Database, e); } - - return imageEntity; } public async findOne( diff --git a/backend/src/collections/role-db/role-db.service.ts b/backend/src/collections/role-db/role-db.service.ts index f38a870..b21c3a5 100644 --- a/backend/src/collections/role-db/role-db.service.ts +++ b/backend/src/collections/role-db/role-db.service.ts @@ -141,6 +141,7 @@ export class RoleDbService { try { const found = await this.rolesRepository.find({ where: { name: In(names) }, + order: { name: 'ASC' }, }); if (!found) return Fail(FT.NotFound, 'No roles found'); @@ -152,7 +153,9 @@ export class RoleDbService { public async findAll(): AsyncFailable { try { - const found = await this.rolesRepository.find(); + const found = await this.rolesRepository.find({ + order: { name: 'ASC' }, + }); if (!found) return Fail(FT.NotFound, 'No roles found'); return found; } catch (e) { diff --git a/backend/src/collections/user-db/user-db.service.ts b/backend/src/collections/user-db/user-db.service.ts index 70d5ab6..84d576e 100644 --- a/backend/src/collections/user-db/user-db.service.ts +++ b/backend/src/collections/user-db/user-db.service.ts @@ -224,6 +224,7 @@ export class UserDbService { const [users, amount] = await this.usersRepository.findAndCount({ take: count, skip: count * page, + order: { username: 'ASC' }, }); if (users === undefined) return Fail(FT.NotFound, 'Users not found'); diff --git a/backend/src/database/entities/image.entity.ts b/backend/src/database/entities/image.entity.ts index 4f64b80..1fd7cb0 100644 --- a/backend/src/database/entities/image.entity.ts +++ b/backend/src/database/entities/image.entity.ts @@ -24,10 +24,7 @@ export class EImageBackend implements EImage { @Column({ nullable: true, - transformer: { - from: (value: string | null) => (value === null ? undefined : value), - to: (value: string | undefined) => (value === undefined ? null : value), - }, + select: false, }) delete_key?: string; }