Merge branch 'main' of git.targo.ca:Targo/targo_backend
This commit is contained in:
commit
4cdc6dbc56
|
|
@ -6,7 +6,6 @@ import { AuthenticationModule } from './identity-and-account/authentication/auth
|
||||||
import { HealthModule } from './health/health.module';
|
import { HealthModule } from './health/health.module';
|
||||||
import { HealthController } from './health/health.controller';
|
import { HealthController } from './health/health.controller';
|
||||||
import { NotificationsModule } from './modules/notifications/notifications.module';
|
import { NotificationsModule } from './modules/notifications/notifications.module';
|
||||||
import { OauthSessionsModule } from './identity-and-account/oauth-sessions/oauth-sessions.module';
|
|
||||||
import { PreferencesModule } from './identity-and-account/preferences/preferences.module';
|
import { PreferencesModule } from './identity-and-account/preferences/preferences.module';
|
||||||
import { PrismaModule } from './prisma/prisma.module';
|
import { PrismaModule } from './prisma/prisma.module';
|
||||||
import { ScheduleModule } from '@nestjs/schedule';
|
import { ScheduleModule } from '@nestjs/schedule';
|
||||||
|
|
@ -25,7 +24,6 @@ import { TimeAndAttendanceModule } from 'src/time-and-attendance/time-and-attend
|
||||||
// CsvExportModule,
|
// CsvExportModule,
|
||||||
HealthModule,
|
HealthModule,
|
||||||
NotificationsModule,
|
NotificationsModule,
|
||||||
OauthSessionsModule,
|
|
||||||
PayperiodsModule,
|
PayperiodsModule,
|
||||||
PreferencesModule,
|
PreferencesModule,
|
||||||
PrismaModule,
|
PrismaModule,
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
import { Body, Controller, Delete, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
|
||||||
import { OAuthSessions } from '@prisma/client';
|
|
||||||
import { RolesAllowed } from "src/common/decorators/roles.decorators";
|
|
||||||
import { Roles as RoleEnum } from '.prisma/client';
|
|
||||||
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
||||||
import { CreateOauthSessionDto } from '../dtos/create-oauth-session.dto';
|
|
||||||
import { OauthSessionsService } from '../services/oauth-sessions.service';
|
|
||||||
import { UpdateOauthSessionDto } from '../dtos/update-oauth-session.dto';
|
|
||||||
|
|
||||||
@ApiTags('OAuth Sessions')
|
|
||||||
@ApiBearerAuth('sessions')
|
|
||||||
//@UseGuards(JwtAuthGuard)
|
|
||||||
@Controller('oauth-sessions')
|
|
||||||
export class OauthSessionsController {
|
|
||||||
constructor(private readonly oauthSessionsService: OauthSessionsService){}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
// @RolesAllowed(RoleEnum.ADMIN)
|
|
||||||
@ApiOperation({summary: 'Create OAuth session' })
|
|
||||||
@ApiResponse({ status: 201, description: 'OAuth session created', type: CreateOauthSessionDto })
|
|
||||||
@ApiResponse({ status: 400, description: 'Incomplete task or invalid data' })
|
|
||||||
create(@Body()dto: CreateOauthSessionDto): Promise<OAuthSessions> {
|
|
||||||
return this.oauthSessionsService.create(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
//@RolesAllowed(RoleEnum.ADMIN)
|
|
||||||
@ApiOperation({summary: 'Find all OAuth session' })
|
|
||||||
@ApiResponse({ status: 201, description: 'List of OAuth session found', type: CreateOauthSessionDto, isArray: true })
|
|
||||||
@ApiResponse({ status: 400, description: 'List of OAuth session not found' })
|
|
||||||
findAll(): Promise<OAuthSessions[]> {
|
|
||||||
return this.oauthSessionsService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id')
|
|
||||||
//@RolesAllowed(RoleEnum.ADMIN)
|
|
||||||
@ApiOperation({summary: 'Find OAuth session' })
|
|
||||||
@ApiResponse({ status: 201, description: 'OAuth session found', type: CreateOauthSessionDto })
|
|
||||||
@ApiResponse({ status: 400, description: 'OAuth session not found' })
|
|
||||||
findOne(@Param('id') id: string): Promise<OAuthSessions> {
|
|
||||||
return this.oauthSessionsService.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Patch(':id')
|
|
||||||
//@RolesAllowed(RoleEnum.ADMIN)
|
|
||||||
@ApiOperation({summary: 'Update OAuth session' })
|
|
||||||
@ApiResponse({ status: 201, description: 'OAuth session updated', type: CreateOauthSessionDto })
|
|
||||||
@ApiResponse({ status: 400, description: 'OAuth session not found' })
|
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateOauthSessionDto): Promise<OAuthSessions> {
|
|
||||||
return this.oauthSessionsService.update(id,dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete(':id')
|
|
||||||
//@RolesAllowed(RoleEnum.ADMIN)
|
|
||||||
@ApiOperation({summary: 'Delete OAuth session' })
|
|
||||||
@ApiResponse({ status: 201, description: 'OAuth session deleted', type: CreateOauthSessionDto })
|
|
||||||
@ApiResponse({ status: 400, description: 'OAuth session not found' })
|
|
||||||
remove(@Param('id') id: string): Promise<OAuthSessions> {
|
|
||||||
return this.oauthSessionsService.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
import { ApiProperty } from "@nestjs/swagger";
|
|
||||||
import { Type } from "class-transformer";
|
|
||||||
import { IsArray, IsDate, IsOptional, IsString, IsUUID } from "class-validator";
|
|
||||||
|
|
||||||
export class CreateOauthSessionDto {
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'cklwi0vb70000z2z20q6f19qk',
|
|
||||||
description: 'Unique ID of an OAuth token (auto-generated)',
|
|
||||||
})
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'S7A2U8R7O6N6',
|
|
||||||
description: 'User`s unique identification number',
|
|
||||||
})
|
|
||||||
@IsUUID()
|
|
||||||
user_id: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'app.targo.ca',
|
|
||||||
description: 'URL in which the access token is used for',
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
application: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
sid: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'L5O6R4D3/O6F3#T8H4E3&R6I4N6G4S7 ...',
|
|
||||||
description: 'Access token',
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
access_token: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'Th3731102h1p07Th3R1n92',
|
|
||||||
description: 'Refresh token',
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
refresh_token: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: '25/12/3018',
|
|
||||||
description: 'Access token`s expiry date',
|
|
||||||
})
|
|
||||||
@Type(()=> Date)
|
|
||||||
@IsDate()
|
|
||||||
access_token_expiry: Date;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: '26/02/3019',
|
|
||||||
description: 'Refresh token`s expiry date',
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
@Type(()=> Date)
|
|
||||||
@IsDate()
|
|
||||||
@IsOptional()
|
|
||||||
refresh_token_expiry?: Date;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'access tolkiens, email, etc... ',
|
|
||||||
description: 'scopes of infos linked to the access token',
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
@IsArray()
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
scopes?: string[];
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
import { PartialType } from "@nestjs/swagger";
|
|
||||||
import { CreateOauthSessionDto } from "./create-oauth-session.dto";
|
|
||||||
|
|
||||||
export class UpdateOauthSessionDto extends PartialType(CreateOauthSessionDto) {}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
|
||||||
import { OauthSessionsController } from './controllers/oauth-sessions.controller';
|
|
||||||
import { OauthSessionsService } from './services/oauth-sessions.service';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
controllers: [OauthSessionsController],
|
|
||||||
providers: [OauthSessionsService, PrismaService]
|
|
||||||
})
|
|
||||||
export class OauthSessionsModule {}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
|
||||||
import { CreateOauthSessionDto } from '../dtos/create-oauth-session.dto';
|
|
||||||
import { OAuthSessions } from '@prisma/client';
|
|
||||||
import { UpdateOauthSessionDto } from '../dtos/update-oauth-session.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class OauthSessionsService {
|
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
|
||||||
|
|
||||||
async create(dto: CreateOauthSessionDto): Promise<OAuthSessions> {
|
|
||||||
const {
|
|
||||||
user_id,
|
|
||||||
application,
|
|
||||||
access_token,
|
|
||||||
refresh_token,
|
|
||||||
sid,
|
|
||||||
access_token_expiry,
|
|
||||||
refresh_token_expiry,
|
|
||||||
scopes,
|
|
||||||
} = dto;
|
|
||||||
|
|
||||||
return this.prisma.oAuthSessions.create({
|
|
||||||
data: {
|
|
||||||
user_id,
|
|
||||||
application,
|
|
||||||
access_token,
|
|
||||||
refresh_token,
|
|
||||||
sid,
|
|
||||||
access_token_expiry,
|
|
||||||
refresh_token_expiry,
|
|
||||||
scopes,
|
|
||||||
},
|
|
||||||
include: { user: true },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
findAll(): Promise<OAuthSessions[]> {
|
|
||||||
return this.prisma.oAuthSessions.findMany({
|
|
||||||
include: { user: true },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOne(id: string): Promise<OAuthSessions> {
|
|
||||||
const token = await this.prisma.oAuthSessions.findUnique({
|
|
||||||
where: { id },
|
|
||||||
include: { user: true },
|
|
||||||
});
|
|
||||||
if(!token) {
|
|
||||||
throw new NotFoundException(`token #${ id } not found`);
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(id: string, dto: UpdateOauthSessionDto): Promise<OAuthSessions> {
|
|
||||||
await this.findOne(id);
|
|
||||||
const {
|
|
||||||
user_id,
|
|
||||||
application,
|
|
||||||
access_token,
|
|
||||||
refresh_token,
|
|
||||||
access_token_expiry,
|
|
||||||
refresh_token_expiry,
|
|
||||||
scopes,
|
|
||||||
} = dto;
|
|
||||||
|
|
||||||
return this.prisma.oAuthSessions.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<OAuthSessions> {
|
|
||||||
await this.findOne(id);
|
|
||||||
return this.prisma.oAuthSessions.delete({ where: { id }});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -24,7 +24,7 @@ export const toStringFromDate = (date: Date | string): string => {
|
||||||
const year = d.getUTCFullYear();
|
const year = d.getUTCFullYear();
|
||||||
const month = String(d.getUTCMonth() + 1).padStart(2, '0');
|
const month = String(d.getUTCMonth() + 1).padStart(2, '0');
|
||||||
const day = String(d.getUTCDate()).padStart(2, '0');
|
const day = String(d.getUTCDate()).padStart(2, '0');
|
||||||
return `${year}-${month}-${d}`;
|
return `${year}-${month}-${day}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toHHmmFromDate = (input: Date | string): string => {
|
export const toHHmmFromDate = (input: Date | string): string => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user