|
@ -16,20 +16,20 @@ import { |
|
|
import { FileInterceptor } from '@nestjs/platform-express' |
|
|
import { FileInterceptor } from '@nestjs/platform-express' |
|
|
import { diskStorage } from 'multer' |
|
|
import { diskStorage } from 'multer' |
|
|
|
|
|
|
|
|
import { type User } from './user.entity' |
|
|
import { type User } from './entity/user.entity' |
|
|
import { UsersService } from './users.service' |
|
|
import { UsersService } from './users.service' |
|
|
import { UserDto, AvatarUploadDto } from './user.dto' |
|
|
import { UserDto, AvatarUploadDto } from './dto/user.dto' |
|
|
|
|
|
|
|
|
import { AuthenticatedGuard } from 'src/auth/42-auth.guard' |
|
|
import { AuthenticatedGuard } from 'src/auth/42-auth.guard' |
|
|
import { FtUser } from 'src/auth/42.decorator' |
|
|
import { FtUser } from 'src/auth/42.decorator' |
|
|
import { Profile } from 'passport-42' |
|
|
import { Profile } from 'passport-42' |
|
|
|
|
|
|
|
|
import { ApiBody, ApiConsumes } from '@nestjs/swagger' |
|
|
import { ApiBody, ApiConsumes } from '@nestjs/swagger' |
|
|
import { Request, Response } from 'express' |
|
|
import { type Request, Response } from 'express' |
|
|
import { createReadStream } from 'fs' |
|
|
import { createReadStream } from 'fs' |
|
|
import { join } from 'path' |
|
|
import { join } from 'path' |
|
|
|
|
|
|
|
|
@Controller('users') |
|
|
@Controller() |
|
|
export class UsersController { |
|
|
export class UsersController { |
|
|
constructor (private readonly usersService: UsersService) {} |
|
|
constructor (private readonly usersService: UsersService) {} |
|
|
|
|
|
|
|
@ -40,10 +40,8 @@ export class UsersController { |
|
|
|
|
|
|
|
|
@Post() |
|
|
@Post() |
|
|
@UseGuards(AuthenticatedGuard) |
|
|
@UseGuards(AuthenticatedGuard) |
|
|
async create( |
|
|
async create (@Body() payload: UserDto, @FtUser() profile: Profile) { |
|
|
@Body() payload: UserDto, |
|
|
const user = await this.usersService.findUser(profile.id) |
|
|
@FtUser() profile: Profile) { |
|
|
|
|
|
const user = await this.usersService.findUser(profile.id); |
|
|
|
|
|
if (user) { |
|
|
if (user) { |
|
|
return await this.usersService.update(user.id, payload) |
|
|
return await this.usersService.update(user.id, payload) |
|
|
} else { |
|
|
} else { |
|
@ -51,13 +49,25 @@ export class UsersController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Post("invit/:id") |
|
|
@Get('friends') |
|
|
|
|
|
@UseGuards(AuthenticatedGuard) |
|
|
|
|
|
async getFriends (@FtUser() profile: Profile) { |
|
|
|
|
|
return await this.usersService.getFriends(profile.id) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Get('invits') |
|
|
|
|
|
@UseGuards(AuthenticatedGuard) |
|
|
|
|
|
async getInvits (@FtUser() profile: Profile) { |
|
|
|
|
|
return await this.usersService.getInvits(profile.id) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Post('invit/:id') |
|
|
@UseGuards(AuthenticatedGuard) |
|
|
@UseGuards(AuthenticatedGuard) |
|
|
followUser( |
|
|
async invitUser ( |
|
|
@FtUser() profile: Profile, |
|
|
@FtUser() profile: Profile, |
|
|
@Param('id', ParseIntPipe) id: number, |
|
|
@Param('id', ParseIntPipe) id: number |
|
|
) { |
|
|
) { |
|
|
return this.usersService.invit(profile.id, id); |
|
|
return await this.usersService.invit(profile.id, id) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Post('avatar') |
|
|
@Post('avatar') |
|
|