Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/definitions/services/definitions/definitions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,15 @@ export class DefinitionsService {
});
return count === 0;
}

/**
* This updates the user id of all definitions posted by a specific user
*
* @param {number} oldUserId - the current user id
* @param {number} newUserId - the new user id
* @returns {Promise<UpdateResult>} - the update result
*/
async updateUserId(oldUserId: number, newUserId: number): Promise<UpdateResult> {
return await this.definitionsRepository.update({ userId: oldUserId }, { userId: newUserId });
}
}
23 changes: 2 additions & 21 deletions src/users/services/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,8 @@ export class UsersService {
}

// Set all of the user's posted words and definitions to user with id=7
const words = await this.wordsService.findByUserId(id);
const definitions = await this.definitionsService.findByUserId(id);

for (const word of words) {
word.userId = 7;
const updateWordDto: UpdateWordDto = {
FrancoArabicWord: word.francoArabicWord,
arabicWord: word.arabicWord,
userId: 7,
};
await this.wordsService.updateWord(user, word.id, updateWordDto);
}

for (const definition of definitions) {
definition.userId = 7;
await this.definitionsService.updateDefinitionById(
user,
definition.id,
definition,
);
}
await this.wordsService.updateUserId(id, 7);
await this.definitionsService.updateUserId(id, 7);

// Delete the user
return await this.usersRepository.delete(id);
Expand Down
11 changes: 11 additions & 0 deletions src/words/services/words/words.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,15 @@ export class WordsService {
async findByUserId(userId: number): Promise<Word[]> {
return this.wordsRepository.find({ where: { userId } });
}

/**
* This updates the user id of all words posted by a specific user
*
* @param {number} oldUserId - the current user id
* @param {number} newUserId - the new user id
* @returns {Promise<UpdateResult>} - the update result
*/
async updateUserId(oldUserId: number, newUserId: number): Promise<UpdateResult> {
return await this.wordsRepository.update({ userId: oldUserId }, { userId: newUserId });
}
}