cherif helped me fix the queryBuilder, so much better now

This commit is contained in:
Me
2022-12-20 04:37:12 +01:00
parent de06007d60
commit 84488ee407
3 changed files with 39 additions and 33 deletions

View File

@@ -45,8 +45,8 @@ export class FriendshipService {
)
.andWhere(
new Brackets((qb2) => {
qb2.where('friendship.status = :status', {status : FriendshipStatus.ACCEPTED})
// .orWhere('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
qb2.where('friendship.status = :statusA', {statusA : FriendshipStatus.ACCEPTED})
.orWhere('friendship.status = :statusR', {statusR : FriendshipStatus.REQUESTED})
}),
)
.getOne()
@@ -54,34 +54,34 @@ export class FriendshipService {
// console.log('MIDDLE Find one friend by username: ')
// console.log({...friendship})
if (!friendship) {
friendship = await this.friendshipRepository
.createQueryBuilder('friendship')
.where(
new Brackets((qb) => {
qb.where(
new Brackets((subAQb) => {
subAQb.where('friendship.senderUsername = :username', {username : username})
.andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : friendUsername})
})
)
.orWhere(
new Brackets((subBQb) => {
subBQb.where('friendship.senderUsername = :friendUsername', {friendUsername : friendUsername})
.andWhere('friendship.receiverUsername = :username', {username : username})
})
)
}),
)
.andWhere(
new Brackets((qb2) => {
// qb2.where('friendship.status = :status', {status : FriendshipStatus.ACCEPTED})
// .orWhere('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
qb2.where('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
}),
)
.getOne()
}
// if (!friendship) {
// friendship = await this.friendshipRepository
// .createQueryBuilder('friendship')
// .where(
// new Brackets((qb) => {
// qb.where(
// new Brackets((subAQb) => {
// subAQb.where('friendship.senderUsername = :username', {username : username})
// .andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : friendUsername})
// })
// )
// .orWhere(
// new Brackets((subBQb) => {
// subBQb.where('friendship.senderUsername = :friendUsername', {friendUsername : friendUsername})
// .andWhere('friendship.receiverUsername = :username', {username : username})
// })
// )
// }),
// )
// .andWhere(
// new Brackets((qb2) => {
// // qb2.where('friendship.status = :status', {status : FriendshipStatus.ACCEPTED})
// // .orWhere('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
// qb2.where('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
// }),
// )
// .getOne()
// }
// console.log('END Find one friend by username: ')
// console.log({...friendship})
@@ -299,8 +299,8 @@ VS ------------------------------------------------
// const relation = await this.friendshipRepository.findOneBy({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
// const relation = await this.friendshipRepository.findOne({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
// console.log('.service accept friendship')
// console.log({...relation})
console.log('.service accept friendship')
console.log({...relation})
if (!relation[0])
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
// console.log(relation.sender)