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

6
package-lock.json generated Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "group_transcendence",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}

View File

@@ -7,7 +7,7 @@ POSTGRES_DATABASE=transcendance_db
# OAUTH2 42 API
FORTYTWO_CLIENT_ID=u-s4t2ud-49dc7b539bcfe1acb48b928b2b281671c99fc5bfab1faca57a536ab7e0075500
FORTYTWO_CLIENT_SECRET=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
FORTYTWO_CLIENT_SECRET=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
FORTYTWO_CALLBACK_URL=http://transcendance:8080/api/v2/auth/redirect
COOKIE_SECRET=248cdc831110eec8796d7c1edbf79835
# JWT

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)