diff --git a/back/volume/src/users/user.entity.ts b/back/volume/src/users/user.entity.ts index af8a8b6..f928202 100644 --- a/back/volume/src/users/user.entity.ts +++ b/back/volume/src/users/user.entity.ts @@ -39,10 +39,11 @@ export class User { @ManyToMany(() => User) @JoinTable() - followers: User[] - - @ManyToMany(() => User, (user) => user.friends) - friends: User[] + followers: User[]; + + @ManyToMany(() => User) + @JoinTable() + friends: User[]; // @Column({ default: { wr: -1, place: -1 } }) // rank: { wr: number; place: number }; diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index f1886ac..e86f444 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -8,7 +8,6 @@ import { UploadedFile, UseGuards, UseInterceptors, - Req, Res, StreamableFile, BadRequestException @@ -56,9 +55,9 @@ export class UsersController { @UseGuards(AuthenticatedGuard) followUser( @FtUser() profile: Profile, - @Param('id, ParseIntPipe') id: number, + @Param('id', ParseIntPipe) id: number, ) { - this.usersService.invit(profile.id, id); + return this.usersService.invit(profile.id, id); } @Post('avatar') @@ -86,7 +85,7 @@ export class UsersController { @FtUser() profile: Profile, @UploadedFile() file: Express.Multer.File ) { - await this.usersService.addAvatar(profile.id, file.filename) + return await this.usersService.addAvatar(profile.id, file.filename) } @Get('avatar') diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index c8a3a7b..c5ff7ca 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -20,7 +20,13 @@ export class UsersService { } async findUser(ftId: number): Promise { - return await this.usersRepository.findOneBy({ ftId }) + return await this.usersRepository.findOne({ + where: { ftId }, + relations: { + friends: true, + followers: true, + } + }); } async create(userData: UserDto) { @@ -47,27 +53,26 @@ export class UsersService { } async addAvatar(ftId: number, filename: string) { - await this.usersRepository.update(ftId, { + return await this.usersRepository.update(ftId, { avatar: filename }) } async invit(ftId: number, targetFtId: number) { - const user = await this.usersRepository.findOne({ - where: { ftId }, - relations: { friends: true, followers: true }, - }); - const target = await this.usersRepository.findOne({ - where: { ftId: targetFtId }, - relations: { friends: true, followers: true }, - }); - const id = user.followers.findIndex((follower) => follower.ftId == ftId) + const user = await this.findUser(ftId); + const target = await this.findUser(targetFtId); + if (!target) { + return new NotFoundException(`Error: user id ${targetFtId} isn't in our db.`) + } + const id = user.followers.findIndex((follower) => follower.ftId === targetFtId) if (id != -1) { + console.log(`Friend relation complete between ${user.username} and ${target.username}`); user.friends.push(target); target.friends.push(user); user.followers.slice(id, 1); this.usersRepository.save(user); } else { + console.log(`You asked ${target.username} to be your friend.`); target.followers.push(user); } this.usersRepository.save(target); diff --git a/docker-compose.yml b/docker-compose.yml index 86c2dc8..dcba7b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,6 +30,8 @@ services: container_name: postgres image: postgres ports: [5432:5432] + volumes: + - /data/postgres:/data/postgres networks: [transcendence] restart: always env_file: .env @@ -42,6 +44,13 @@ services: - "8080:80" volumes: - /data/pgadmin:/root/.pgadmin - env_file: - - .env + environment: + PGADMIN_DEFAULT_EMAIL: 'usr@usr.com' + PGADMIN_DEFAULT_PASSWORD: 'pw' + GUNICORN_ACCESS_LOGFILE: '/dev/null' + PGADMIN_CONFIG_UPGRADE_CHECK_ENABLED: 'False' + depends_on: + - postgres networks: [transcendence] + logging: + driver: none