Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratatinator97 committed Mar 15, 2024
1 parent c22ff3c commit ab15728
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 51 deletions.
3 changes: 0 additions & 3 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import { Notif } from 'src/entities/notification.entity';

@Injectable()
export class AuthService {
findWithId(userId: number): User | PromiseLike<User> {
throw new Error('Method not implemented.');
}
private logger = new Logger('AuthService');
constructor(
@InjectRepository(UserRepository)
Expand Down
82 changes: 34 additions & 48 deletions src/collection/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -158,7 +156,7 @@ export class CollectionService {
deleteCollectionDto.fatherId,
user,
);
let fatherCollectionsIds = fatherCollection.collections.map(
const fatherCollectionsIds = fatherCollection.collections.map(
(collection) => {
return collection.id;
},
Expand Down Expand Up @@ -333,38 +331,6 @@ export class CollectionService {
}
}

async deleteCollection(deleteCollectionDto: deleteCollectionDto, user: User): Promise<void>{
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,
Expand Down Expand Up @@ -612,18 +578,38 @@ export class CollectionService {
return await this.getCollectionById(fatherCollectionId, user);
}

async deleteAllCollections(user: User): Promise<void>{
async deleteAllCollections(user: User): Promise<void> {
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`);
}
}
}

0 comments on commit ab15728

Please sign in to comment.