Merge branch 'main' of git.targo.ca:Targo/targo_backend into origin/dev/setup/AuthMiddleware/NicolasD
pulling main changes for up-to-date CRUD
This commit is contained in:
commit
11cdd8337d
|
|
@ -5,9 +5,27 @@ import { PrismaModule } from './prisma/prisma.module';
|
|||
import { HealthModule } from './health/health.module';
|
||||
import { HealthController } from './health/health.controller';
|
||||
import { UsersModule } from './modules/users-management/users.module';
|
||||
import { OauthAccessTokensModule } from './modules/oauth-access-tokens/oauth-access-tokens.module';
|
||||
import { CustomersModule } from './modules/customers/customers.module';
|
||||
import { EmployeesModule } from './modules/employees/employees.module';
|
||||
import { LeaveRequestsModule } from './modules/leave_requests/leave-requests.module';
|
||||
import { ShiftCodeModule } from './modules/shift-codes/shift-codes.module';
|
||||
import { ShiftsModule } from './modules/shifts/shifts.module';
|
||||
import { TimesheetsModule } from './modules/timesheets/timesheets.module';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, HealthModule, UsersModule],
|
||||
imports: [
|
||||
PrismaModule,
|
||||
HealthModule,
|
||||
UsersModule,
|
||||
OauthAccessTokensModule,
|
||||
CustomersModule,
|
||||
EmployeesModule,
|
||||
LeaveRequestsModule,
|
||||
ShiftCodeModule,
|
||||
ShiftsModule,
|
||||
TimesheetsModule,
|
||||
],
|
||||
controllers: [AppController, HealthController],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import { OauthAccessTokensService } from '../services/oauth-access-tokens.service';
|
||||
import { CreateOauthAccessTokenDto } from '../dtos/create-oauth-access-token.dto';
|
||||
import { OAuthAccessTokens } from '@prisma/client';
|
||||
import { UpdateOauthAccessTokenDto } from '../dtos/update-oauth-access-token.dto';
|
||||
|
||||
@Controller('oauth-access-tokens')
|
||||
export class OauthAccessTokensController {
|
||||
constructor(private readonly oauthAccessTokensService: OauthAccessTokensService){}
|
||||
|
||||
@Post()
|
||||
create(@Body()dto: CreateOauthAccessTokenDto): Promise<OAuthAccessTokens> {
|
||||
return this.oauthAccessTokensService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll(): Promise<OAuthAccessTokens[]> {
|
||||
return this.oauthAccessTokensService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string): Promise<OAuthAccessTokens> {
|
||||
return this.oauthAccessTokensService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdateOauthAccessTokenDto): Promise<OAuthAccessTokens> {
|
||||
return this.oauthAccessTokensService.update(id,dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string): Promise<OAuthAccessTokens> {
|
||||
return this.oauthAccessTokensService.remove(id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import { Type } from "class-transformer";
|
||||
import { IsArray, IsDate, IsOptional, IsString, IsUUID } from "class-validator";
|
||||
|
||||
export class CreateOauthAccessTokenDto {
|
||||
|
||||
@IsUUID()
|
||||
user_id: string;
|
||||
|
||||
@IsString()
|
||||
application: string;
|
||||
|
||||
@IsString()
|
||||
access_token: string;
|
||||
|
||||
@IsString()
|
||||
refresh_token: string;
|
||||
|
||||
@Type(()=> Date)
|
||||
@IsDate()
|
||||
access_token_expiry: Date;
|
||||
|
||||
@Type(()=> Date)
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
refresh_token_expiry?: Date;
|
||||
|
||||
@IsArray()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
scopes?: string[];
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateOauthAccessTokenDto } from "./create-oauth-access-token.dto";
|
||||
|
||||
export class UpdateOauthAccessTokenDto extends PartialType(CreateOauthAccessTokenDto) {}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { OauthAccessTokensController } from './controllers/oauth-access-tokens.controller';
|
||||
import { OauthAccessTokensService } from './services/oauth-access-tokens.service';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
controllers: [OauthAccessTokensController],
|
||||
providers: [OauthAccessTokensService, PrismaService]
|
||||
})
|
||||
export class OauthAccessTokensModule {}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
import { CreateOauthAccessTokenDto } from '../dtos/create-oauth-access-token.dto';
|
||||
import { OAuthAccessTokens } from '@prisma/client';
|
||||
import { UpdateOauthAccessTokenDto } from '../dtos/update-oauth-access-token.dto';
|
||||
|
||||
@Injectable()
|
||||
export class OauthAccessTokensService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async create(dto: CreateOauthAccessTokenDto): Promise<OAuthAccessTokens> {
|
||||
const {
|
||||
user_id,
|
||||
application,
|
||||
access_token,
|
||||
refresh_token,
|
||||
access_token_expiry,
|
||||
refresh_token_expiry,
|
||||
scopes,
|
||||
} = dto;
|
||||
|
||||
return this.prisma.oAuthAccessTokens.create({
|
||||
data: {
|
||||
user_id,
|
||||
application,
|
||||
access_token,
|
||||
refresh_token,
|
||||
access_token_expiry,
|
||||
refresh_token_expiry,
|
||||
scopes,
|
||||
},
|
||||
include: { user: true },
|
||||
});
|
||||
}
|
||||
|
||||
findAll(): Promise<OAuthAccessTokens[]> {
|
||||
return this.prisma.oAuthAccessTokens.findMany({
|
||||
include: { user: true },
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<OAuthAccessTokens> {
|
||||
const token = await this.prisma.oAuthAccessTokens.findUnique({
|
||||
where: { id },
|
||||
include: { user: true },
|
||||
});
|
||||
if(!token) {
|
||||
throw new NotFoundException(`token #${ id } not found`);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
async update(id: string, dto: UpdateOauthAccessTokenDto): Promise<OAuthAccessTokens> {
|
||||
await this.findOne(id);
|
||||
const {
|
||||
user_id,
|
||||
application,
|
||||
access_token,
|
||||
refresh_token,
|
||||
access_token_expiry,
|
||||
refresh_token_expiry,
|
||||
scopes,
|
||||
} = dto;
|
||||
|
||||
return this.prisma.oAuthAccessTokens.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...(user_id !== undefined && { user_id }),
|
||||
...(application !== undefined && { application }),
|
||||
...(access_token !== undefined && { access_token }),
|
||||
...(refresh_token !== undefined && { refresh_token }),
|
||||
...(access_token_expiry !== undefined && { access_token_expiry }),
|
||||
...(refresh_token_expiry !== undefined && { refresh_token_expiry }),
|
||||
...(scopes !== undefined && { scopes }),
|
||||
},
|
||||
include: { user: true },
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<OAuthAccessTokens> {
|
||||
await this.findOne(id);
|
||||
return this.prisma.oAuthAccessTokens.delete({ where: { id }});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user