Update the ImageHelper to check an entity's count
All checks were successful
Test / build (push) Successful in 9s

This commit is contained in:
Ethan Lane 2024-07-10 17:00:51 +01:00
parent bdb6f3da3d
commit 3b9706ae94
2 changed files with 9 additions and 1 deletions

View file

@ -47,6 +47,14 @@ export default class Inventory extends AppBaseEntity {
return single;
}
public static async ExistsByCardNumberAndUserId(userId: string, cardNumber: string): Promise<boolean> {
const repository = AppDataSource.getRepository(Inventory);
const count = await repository.count({ where: { UserId: userId, CardNumber: cardNumber }});
return count != 0;
}
public static async FetchAllByUserId(userId: string): Promise<Inventory[]> {
const repository = AppDataSource.getRepository(Inventory);

View file

@ -39,7 +39,7 @@ export default class ImageHelper {
const imageData = await Jimp.read(filePath);
if (userId != null) {
const claimed = await Inventory.FetchOneByCardNumberAndUserId(userId, card.id) != null;
const claimed = await Inventory.ExistsByCardNumberAndUserId(userId, card.id);
if (!claimed) {
imageData.greyscale();