diff --git a/back/volume/package-lock.json b/back/volume/package-lock.json index 875da92..472814f 100644 --- a/back/volume/package-lock.json +++ b/back/volume/package-lock.json @@ -28,7 +28,7 @@ "@types/express": "^4.17.13", "@types/express-session": "^1.17.6", "@types/multer": "^1.4.7", - "@types/node": "^16.0.0", + "@types/node": "^16.18.14", "@types/passport": "^1.0.12", "@types/ws": "^8.5.3", "bcrypt": "^5.1.0", @@ -2336,9 +2336,9 @@ } }, "node_modules/@types/node": { - "version": "16.18.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.3.tgz", - "integrity": "sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg==" + "version": "16.18.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.14.tgz", + "integrity": "sha512-wvzClDGQXOCVNU4APPopC2KtMYukaF1MN/W3xAmslx22Z4/IF1/izDMekuyoUlwfnDHYCIZGaj7jMwnJKBTxKw==" }, "node_modules/@types/parse-json": { "version": "4.0.0", @@ -12716,9 +12716,9 @@ } }, "@types/node": { - "version": "16.18.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.3.tgz", - "integrity": "sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg==" + "version": "16.18.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.14.tgz", + "integrity": "sha512-wvzClDGQXOCVNU4APPopC2KtMYukaF1MN/W3xAmslx22Z4/IF1/izDMekuyoUlwfnDHYCIZGaj7jMwnJKBTxKw==" }, "@types/parse-json": { "version": "4.0.0", diff --git a/back/volume/package.json b/back/volume/package.json index bc15b31..de8efb2 100644 --- a/back/volume/package.json +++ b/back/volume/package.json @@ -40,7 +40,7 @@ "@types/express": "^4.17.13", "@types/express-session": "^1.17.6", "@types/multer": "^1.4.7", - "@types/node": "^16.0.0", + "@types/node": "^16.18.14", "@types/passport": "^1.0.12", "@types/ws": "^8.5.3", "bcrypt": "^5.1.0", diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index 23fa80f..3c54471 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -37,7 +37,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { async handleConnection (socket: Socket) { try { - const user: User = await this.userService.findUser(socket.data.user.ftId) + const user: User | null = await this.userService.findUser(socket.data.user.ftId) if (!user) { socket.emit('Error', new UnauthorizedException()) // socket.disconnect(); @@ -62,10 +62,12 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { async onCreateChannel ( socket: Socket, @MessageBody() channeldto: CreateChannelDto - ): Promise { + ): Promise { const channel = new Channel() channel.name = channeldto.name const owner = await this.userService.findUser(channeldto.owner) + if (!owner) + return null; channel.owners.push(owner) channel.password = channeldto.password /// .../// @@ -96,7 +98,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { const channel = await this.chatService.getChannel( createdMessage.channel.id ) - const users = await this.userService.findOnlineInChannel(channel) + if (channel) { + const users = await this.userService.findOnlineInChannel(channel) + } /// TODO: Send message to users } } diff --git a/back/volume/src/main.ts b/back/volume/src/main.ts index 33750d9..243ca57 100644 --- a/back/volume/src/main.ts +++ b/back/volume/src/main.ts @@ -11,7 +11,7 @@ import * as cookieParser from 'cookie-parser' async function bootstrap () { const logger = new Logger() const app = await NestFactory.create(AppModule) - const port = process.env.BACK_PORT + const port = process.env.BACK_PORT! const cors = { origin: ['http://localhost:80', 'http://localhost', '*'], methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS', @@ -24,7 +24,7 @@ async function bootstrap () { session({ resave: false, saveUninitialized: false, - secret: process.env.JWT_SECRET + secret: process.env.JWT_SECRET! }) ) app.use(cookieParser()) @@ -32,7 +32,7 @@ async function bootstrap () { app.use(passport.session()) app.enableCors(cors) app.useWebSocketAdapter(new WsAdapter(app)) - await app.listen(port) - logger.log(`Application listening on port ${port}`) + await app.listen(port) + logger.log(`Application listening on port ${port}`) } bootstrap() diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index ba6c3df..26300cc 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -44,13 +44,13 @@ export class UsersController { } @Get(':id') - async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise { + async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise { return await this.usersService.findUser(ftId) } @Get() @UseGuards(AuthenticatedGuard) - async getUser (@FtUser() profile: Profile): Promise { + async getUser (@FtUser() profile: Profile): Promise { return await this.usersService.findUser(profile.id) } @@ -114,12 +114,13 @@ export class UsersController { return await this.usersService.addAvatar(profile.id, file.filename) } - @Get('avatar') - async getAvatar ( - @FtUser() profile: Profile, + @Get(':id/avatar') + async getAvatarById ( + @Param('id', ParseIntPipe) ftId: number, @Res({ passthrough: true }) response: Response ) { - const user = await this.usersService.findUser(profile.id) + const user = await this.usersService.findUser(ftId) + if (!user) return const filename = user.avatar const stream = createReadStream(join(process.cwd(), 'avatars/' + filename)) response.set({ @@ -128,4 +129,12 @@ export class UsersController { }) return new StreamableFile(stream) } + + @Get('avatar') + async getAvatar ( + @FtUser() profile: Profile, + @Res({ passthrough: true }) response: Response + ) { + return await this.getAvatarById(profile.id, response); + } } diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index 379466e..21f090c 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -44,8 +44,9 @@ export class UsersService { .getMany() } - async update (ftId: number, changes: UserDto) { + async update (ftId: number, changes: UserDto):Promise < User | null> { const updatedUser = await this.findUser(ftId) + if (!updatedUser) return null this.usersRepository.merge(updatedUser, changes) return await this.usersRepository.save(updatedUser) } @@ -56,13 +57,14 @@ export class UsersService { }) } - async getFriends (ftId: number) { + async getFriends (ftId: number): Promise< User[] >{ const user = await this.usersRepository.findOne({ where: { ftId }, relations: { friends: true } }) + if (!user) return [] return user.friends } @@ -73,11 +75,13 @@ export class UsersService { followers: true } }) + if (!user) return null return user.followers } async invit (ftId: number, targetFtId: number) { const user = await this.findUser(ftId) + if (!user) return null const target = await this.findUser(targetFtId) if (target == null) { return new NotFoundException(