Browse Source

lint errors

master
nicolas-arnaud 2 years ago
parent
commit
5cd6d55390
  1. 14
      back/volume/package-lock.json
  2. 2
      back/volume/package.json
  3. 10
      back/volume/src/chat/chat.gateway.ts
  4. 8
      back/volume/src/main.ts
  5. 21
      back/volume/src/users/users.controller.ts
  6. 8
      back/volume/src/users/users.service.ts

14
back/volume/package-lock.json

@ -28,7 +28,7 @@
"@types/express": "^4.17.13", "@types/express": "^4.17.13",
"@types/express-session": "^1.17.6", "@types/express-session": "^1.17.6",
"@types/multer": "^1.4.7", "@types/multer": "^1.4.7",
"@types/node": "^16.0.0", "@types/node": "^16.18.14",
"@types/passport": "^1.0.12", "@types/passport": "^1.0.12",
"@types/ws": "^8.5.3", "@types/ws": "^8.5.3",
"bcrypt": "^5.1.0", "bcrypt": "^5.1.0",
@ -2336,9 +2336,9 @@
} }
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "16.18.3", "version": "16.18.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.3.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.14.tgz",
"integrity": "sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg==" "integrity": "sha512-wvzClDGQXOCVNU4APPopC2KtMYukaF1MN/W3xAmslx22Z4/IF1/izDMekuyoUlwfnDHYCIZGaj7jMwnJKBTxKw=="
}, },
"node_modules/@types/parse-json": { "node_modules/@types/parse-json": {
"version": "4.0.0", "version": "4.0.0",
@ -12716,9 +12716,9 @@
} }
}, },
"@types/node": { "@types/node": {
"version": "16.18.3", "version": "16.18.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.3.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.14.tgz",
"integrity": "sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg==" "integrity": "sha512-wvzClDGQXOCVNU4APPopC2KtMYukaF1MN/W3xAmslx22Z4/IF1/izDMekuyoUlwfnDHYCIZGaj7jMwnJKBTxKw=="
}, },
"@types/parse-json": { "@types/parse-json": {
"version": "4.0.0", "version": "4.0.0",

2
back/volume/package.json

@ -40,7 +40,7 @@
"@types/express": "^4.17.13", "@types/express": "^4.17.13",
"@types/express-session": "^1.17.6", "@types/express-session": "^1.17.6",
"@types/multer": "^1.4.7", "@types/multer": "^1.4.7",
"@types/node": "^16.0.0", "@types/node": "^16.18.14",
"@types/passport": "^1.0.12", "@types/passport": "^1.0.12",
"@types/ws": "^8.5.3", "@types/ws": "^8.5.3",
"bcrypt": "^5.1.0", "bcrypt": "^5.1.0",

10
back/volume/src/chat/chat.gateway.ts

@ -37,7 +37,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async handleConnection (socket: Socket) { async handleConnection (socket: Socket) {
try { 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) { if (!user) {
socket.emit('Error', new UnauthorizedException()) socket.emit('Error', new UnauthorizedException())
// socket.disconnect(); // socket.disconnect();
@ -62,10 +62,12 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async onCreateChannel ( async onCreateChannel (
socket: Socket, socket: Socket,
@MessageBody() channeldto: CreateChannelDto @MessageBody() channeldto: CreateChannelDto
): Promise<Channel> { ): Promise<Channel | null> {
const channel = new Channel() const channel = new Channel()
channel.name = channeldto.name channel.name = channeldto.name
const owner = await this.userService.findUser(channeldto.owner) const owner = await this.userService.findUser(channeldto.owner)
if (!owner)
return null;
channel.owners.push(owner) channel.owners.push(owner)
channel.password = channeldto.password channel.password = channeldto.password
/// .../// /// ...///
@ -96,7 +98,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
const channel = await this.chatService.getChannel( const channel = await this.chatService.getChannel(
createdMessage.channel.id createdMessage.channel.id
) )
const users = await this.userService.findOnlineInChannel(channel) if (channel) {
const users = await this.userService.findOnlineInChannel(channel)
}
/// TODO: Send message to users /// TODO: Send message to users
} }
} }

8
back/volume/src/main.ts

@ -11,7 +11,7 @@ import * as cookieParser from 'cookie-parser'
async function bootstrap () { async function bootstrap () {
const logger = new Logger() const logger = new Logger()
const app = await NestFactory.create<NestExpressApplication>(AppModule) const app = await NestFactory.create<NestExpressApplication>(AppModule)
const port = process.env.BACK_PORT const port = process.env.BACK_PORT!
const cors = { const cors = {
origin: ['http://localhost:80', 'http://localhost', '*'], origin: ['http://localhost:80', 'http://localhost', '*'],
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS', methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS',
@ -24,7 +24,7 @@ async function bootstrap () {
session({ session({
resave: false, resave: false,
saveUninitialized: false, saveUninitialized: false,
secret: process.env.JWT_SECRET secret: process.env.JWT_SECRET!
}) })
) )
app.use(cookieParser()) app.use(cookieParser())
@ -32,7 +32,7 @@ async function bootstrap () {
app.use(passport.session()) app.use(passport.session())
app.enableCors(cors) app.enableCors(cors)
app.useWebSocketAdapter(new WsAdapter(app)) app.useWebSocketAdapter(new WsAdapter(app))
await app.listen(port) await app.listen(port)
logger.log(`Application listening on port ${port}`) logger.log(`Application listening on port ${port}`)
} }
bootstrap() bootstrap()

21
back/volume/src/users/users.controller.ts

@ -44,13 +44,13 @@ export class UsersController {
} }
@Get(':id') @Get(':id')
async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise<User> { async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise<User | null> {
return await this.usersService.findUser(ftId) return await this.usersService.findUser(ftId)
} }
@Get() @Get()
@UseGuards(AuthenticatedGuard) @UseGuards(AuthenticatedGuard)
async getUser (@FtUser() profile: Profile): Promise<User> { async getUser (@FtUser() profile: Profile): Promise<User | null> {
return await this.usersService.findUser(profile.id) return await this.usersService.findUser(profile.id)
} }
@ -114,12 +114,13 @@ export class UsersController {
return await this.usersService.addAvatar(profile.id, file.filename) return await this.usersService.addAvatar(profile.id, file.filename)
} }
@Get('avatar') @Get(':id/avatar')
async getAvatar ( async getAvatarById (
@FtUser() profile: Profile, @Param('id', ParseIntPipe) ftId: number,
@Res({ passthrough: true }) response: Response @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 filename = user.avatar
const stream = createReadStream(join(process.cwd(), 'avatars/' + filename)) const stream = createReadStream(join(process.cwd(), 'avatars/' + filename))
response.set({ response.set({
@ -128,4 +129,12 @@ export class UsersController {
}) })
return new StreamableFile(stream) return new StreamableFile(stream)
} }
@Get('avatar')
async getAvatar (
@FtUser() profile: Profile,
@Res({ passthrough: true }) response: Response
) {
return await this.getAvatarById(profile.id, response);
}
} }

8
back/volume/src/users/users.service.ts

@ -44,8 +44,9 @@ export class UsersService {
.getMany() .getMany()
} }
async update (ftId: number, changes: UserDto) { async update (ftId: number, changes: UserDto):Promise < User | null> {
const updatedUser = await this.findUser(ftId) const updatedUser = await this.findUser(ftId)
if (!updatedUser) return null
this.usersRepository.merge(updatedUser, changes) this.usersRepository.merge(updatedUser, changes)
return await this.usersRepository.save(updatedUser) 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({ const user = await this.usersRepository.findOne({
where: { ftId }, where: { ftId },
relations: { relations: {
friends: true friends: true
} }
}) })
if (!user) return []
return user.friends return user.friends
} }
@ -73,11 +75,13 @@ export class UsersService {
followers: true followers: true
} }
}) })
if (!user) return null
return user.followers return user.followers
} }
async invit (ftId: number, targetFtId: number) { async invit (ftId: number, targetFtId: number) {
const user = await this.findUser(ftId) const user = await this.findUser(ftId)
if (!user) return null
const target = await this.findUser(targetFtId) const target = await this.findUser(targetFtId)
if (target == null) { if (target == null) {
return new NotFoundException( return new NotFoundException(

Loading…
Cancel
Save