Browse Source

all route

master
nicolas-arnaud 2 years ago
parent
commit
807393ee8f
  1. 27
      README.md
  2. 10
      back/volume/src/users/users.controller.ts
  3. 8
      back/volume/src/users/users.service.ts

27
README.md

@ -15,19 +15,22 @@ If you not use rootless docker, either rename Makesudo as Makefile or call `make
rename .env_sample to .env and customize it to your needs and credentials. rename .env_sample to .env and customize it to your needs and credentials.
## Back endpoints: ## Back endpoints:
|Method|endpoint|description| |Method|endpoint|description|account securised?|
|:---:|:---:|:---:| |:---:|:---:|:---:|
|GET |/log/in |the login using 42 api.| |GET |/log/in |the login using 42 api.|☑|
|GET |/log/inReturn |the 42 api callback.| |GET |/log/inReturn |the 42 api callback.|☑|
|GET |/log/profile |get user 42's datas.| |GET |/log/profile |get connected user 42's datas.|☑|
|GET |/log/out |log out user.| |GET |/log/out |log out user.|☑|
|GET |/ |return user datas.| |GET |/all |return all users publics datas.|☒|
|POST|/ |update user datas.| |GET |/online |return all online users's public datas.|☒|
|GET |/friends |return users which are friends.| |GET |/:id |return ftId: id's public datas|☒|
|GET |/invits |return users which invited user to be friend.| |GET |/ |return connected user public datas|☑|
|POST|/invit/:id |invit user whith ftId: id as friend.| |POST|/ |update user datas.|☑|
|GET |/avatar |return the user avatar| |GET |/friends |return users which are friends.|☑|
|POST|/avatar |set a user avatar with multipart post upload.| |GET |/invits |return users which invited user to be friend.|☑|
|POST|/invit/:id |invit user whith ftId: id as friend.|☑|
|GET |/avatar |return the user avatar|☒|
|POST|/avatar |set a user avatar with multipart post upload.|☑|
## Dependencies: ## Dependencies:

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

@ -33,7 +33,7 @@ import { join } from 'path'
export class UsersController { export class UsersController {
constructor (private readonly usersService: UsersService) {} constructor (private readonly usersService: UsersService) {}
@Get() @Get('all')
async getAllUsers (): Promise<User[]> { async getAllUsers (): Promise<User[]> {
return await this.usersService.findUsers() return await this.usersService.findUsers()
} }
@ -44,10 +44,16 @@ export class UsersController {
} }
@Get(':id') @Get(':id')
async getUser (@Param('id', ParseIntPipe) ftId: number): Promise<User> { async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise<User> {
return await this.usersService.findUser(ftId) return await this.usersService.findUser(ftId)
} }
@Get()
@UseGuards(AuthenticatedGuard)
async getUser (@FtUser() profile: Profile): Promise<User> {
return await this.usersService.findUser(profile.id)
}
@Post() @Post()
@UseGuards(AuthenticatedGuard) @UseGuards(AuthenticatedGuard)
async create (@Body() payload: UserDto, @FtUser() profile: Profile) { async create (@Body() payload: UserDto, @FtUser() profile: Profile) {

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

@ -23,6 +23,10 @@ export class UsersService {
return await this.usersRepository.findOneBy({ ftId }) return await this.usersRepository.findOneBy({ ftId })
} }
async findOnlineUsers (): Promise<User[]> {
return await this.usersRepository.find({ where: { status: 'online' } })
}
async create (userData: UserDto) { async create (userData: UserDto) {
try { try {
const newUser = this.usersRepository.create(userData) const newUser = this.usersRepository.create(userData)
@ -56,7 +60,7 @@ export class UsersService {
const user = await this.usersRepository.findOne({ const user = await this.usersRepository.findOne({
where: { ftId }, where: { ftId },
relations: { relations: {
friends: true, friends: true
} }
}) })
return user.friends return user.friends
@ -66,7 +70,7 @@ export class UsersService {
const user = await this.usersRepository.findOne({ const user = await this.usersRepository.findOne({
where: { ftId }, where: { ftId },
relations: { relations: {
followers: true, followers: true
} }
}) })
return user.followers return user.followers

Loading…
Cancel
Save