From ab15728213a675a147eb88d885c9d9e7c95d0af9 Mon Sep 17 00:00:00 2001 From: Alexandros SIDIRAS Date: Fri, 15 Mar 2024 11:51:46 +0100 Subject: [PATCH] fix merge issues --- src/auth/auth.service.ts | 3 - src/collection/collection.service.ts | 82 ++++++++++++---------------- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 95e7a15..c443ad8 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -14,9 +14,6 @@ import { Notif } from 'src/entities/notification.entity'; @Injectable() export class AuthService { - findWithId(userId: number): User | PromiseLike { - throw new Error('Method not implemented.'); - } private logger = new Logger('AuthService'); constructor( @InjectRepository(UserRepository) diff --git a/src/collection/collection.service.ts b/src/collection/collection.service.ts index 65ce8aa..04b3eb3 100644 --- a/src/collection/collection.service.ts +++ b/src/collection/collection.service.ts @@ -55,10 +55,8 @@ export class CollectionService { if (!collection) { throw new NotFoundException(`Collection with ID '${id}' not found`); } else { - let viewer: number; - let editor: number; - viewer = collection.viewers.indexOf(user?.username); - editor = collection.editors.indexOf(user?.username); + const viewer: number = collection.viewers.indexOf(user?.username); + const editor: number = collection.editors.indexOf(user?.username); if ( collection.public === true || viewer != -1 || @@ -158,7 +156,7 @@ export class CollectionService { deleteCollectionDto.fatherId, user, ); - let fatherCollectionsIds = fatherCollection.collections.map( + const fatherCollectionsIds = fatherCollection.collections.map( (collection) => { return collection.id; }, @@ -333,38 +331,6 @@ export class CollectionService { } } - async deleteCollection(deleteCollectionDto: deleteCollectionDto, user: User): Promise{ - const collection = await this.getCollectionById(deleteCollectionDto.collectionId, user); - if(deleteCollectionDto.fatherId){ - deleteCollectionDto.fatherId=Number(deleteCollectionDto.fatherId); - const fatherCollection = await this.getCollectionById(deleteCollectionDto.fatherId, user); - let fatherCollectionsIds = fatherCollection.collections.map(collection => {return collection.id;}) - fatherCollectionsIds.splice(fatherCollectionsIds.indexOf(deleteCollectionDto.collectionId),1); - const modifyCollectionDto : modifyCollectionDto = { - meaning : null, - speech : null, - pictoIds : null, - priority : 10, - color : null, - collectionIds : fatherCollectionsIds, - pictohubId: null - } - await this.modifyCollection(deleteCollectionDto.fatherId, user, modifyCollectionDto, null); - } - try{ - const result = await this.collectionRepository.delete({ - id: deleteCollectionDto.collectionId, - userId: user.id, - }); - } catch(error){ - if(error.code === "23503"){ - return; - } else { - throw new InternalServerErrorException(`couldn't delete collection with id ${deleteCollectionDto.collectionId}`); - } - } - } - async createNotif( collection: Collection, user: User, @@ -612,18 +578,38 @@ export class CollectionService { return await this.getCollectionById(fatherCollectionId, user); } - async deleteAllCollections(user: User): Promise{ + async deleteAllCollections(user: User): Promise { const collections = await this.getAllUserCollections(user); console.log(`User ${user.username} has ${collections.length} collections`); - try{ - await Promise.all(collections.map(collection => - this.modifyCollection(collection.id, user, {meaning: null, speech: null, priority: null, color: null, pictohubId: null, collectionIds: [], pictoIds: []}, null) - )); - await Promise.all(collections.map(collection => - this.deleteCollection({collectionId: collection.id, fatherId: null}, user) - )); - } catch(error){ - throw new InternalServerErrorException(`couldn't delete all collections`); + try { + await Promise.all( + collections.map((collection) => + this.modifyCollection( + collection.id, + user, + { + meaning: null, + speech: null, + priority: null, + color: null, + pictohubId: null, + collectionIds: [], + pictoIds: [], + }, + null, + ), + ), + ); + await Promise.all( + collections.map((collection) => + this.deleteCollection( + { collectionId: collection.id, fatherId: null }, + user, + ), + ), + ); + } catch (error) { + throw new InternalServerErrorException(`couldn't delete all collections`); } + } } -