Skip to content

Commit

Permalink
Update Services
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyZeroZx committed Sep 22, 2022
1 parent 6ecf562 commit 7d37164
Show file tree
Hide file tree
Showing 29 changed files with 309 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"node": "16.16.0"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node dist/main",
Expand Down
4 changes: 3 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ScheduleModule as ScheduleModuleNestJs } from '@nestjs/schedule';
import { ChargueModule } from './chargue/chargue.module';
import { AttendanceModule } from './attendance/attendance.module';
import { ScheduleModule } from './schedule/schedule.module';
import { LicenceModule } from './licence/licence.module';

@Module({
imports: [
Expand Down Expand Up @@ -52,7 +53,8 @@ import { ScheduleModule } from './schedule/schedule.module';
TaskToUserModule,
ChargueModule,
AttendanceModule,
ScheduleModule
ScheduleModule,
LicenceModule
],
controllers: [AppController],
providers: [AppService],
Expand Down
3 changes: 2 additions & 1 deletion src/attendance/attendance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class AttendanceService {
return { message: Constant.MENSAJE_OK, info: 'Se registro exitosamente su salida' };
}
this.logger.warn(`Sucedio un error al actualizar el Attendance`);
return { message: 'Sucedio un error al actualizar el Attendance' };
throw new InternalServerErrorException('Sucedio un error al actualizar Attendance');
} catch (error) {
this.logger.error({
message: `Sucedio un error al actualizar Attendance para el usuario ${user.name}`,
Expand Down Expand Up @@ -156,6 +156,7 @@ export class AttendanceService {
.addSelect('ATTENDANCE.isActive', 'isActive')
.addSelect('ATTENDANCE.isLater', 'isLater')
.addSelect('ATTENDANCE.isAbsent', 'isAbsent')
.addSelect('ATTENDANCE.isDayOff', 'isDayOff')
.innerJoin(User, 'USER', 'USER.id = ATTENDANCE.codUser')
.where('USER.id =:id', { id: id })
.orderBy('ATTENDANCE.date', 'DESC')
Expand Down
5 changes: 5 additions & 0 deletions src/attendance/entities/attendance.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Attendance {
@IsOptional()
description: string;

// Reference is check attendance today
@Column('boolean', { default: true })
isActive: boolean;

Expand All @@ -48,4 +49,8 @@ export class Attendance {

@UpdateDateColumn({ type: 'timestamp' })
exitTime: Date;

@Column('boolean', { default: false })
@IsOptional()
isDayOff: boolean;
}
11 changes: 7 additions & 4 deletions src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ describe('AuthController', () => {
// En caso contario cualquier otro usuario como el status bloqueado no puede logearse
let userBloqueado = AuthMockService.userResetado;
userBloqueado.status = Constant.STATUS_USER.BLOQUEADO;
const loginBloqueado: any = await controller.login(AuthMockService.loginDto, userBloqueado);
const loginBloqueado: any = controller.login(AuthMockService.loginDto, userBloqueado);

await expect(loginBloqueado).rejects.toThrowError(
new BadRequestException({
message: `El usuario tiene un status ${userBloqueado.status}`,
}),
);
expect(spyGenerateToken).not.toBeCalledTimes(4);
expect(loginBloqueado).toEqual({
message: `El usuario tiene un status ${userBloqueado.status}`,
});
});

it('Validamos generateRegistration', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class AuthController {
Object.assign(data, { message: Constant.MENSAJE_OK });
return data;
default:
return { message: `El usuario tiene un status ${user.status}` };
new BadRequestException(`El usuario tiene un status ${user.status}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/chargue/chargue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ChargueService {
}

this.logger.warn('Sucedio un error al actualizar el chargue');
return { message: 'Sucedio un error al actualizar el chargue' };
throw new InternalServerErrorException('Sucedio un error al actualizar el chargue');
} catch (error) {
this.logger.error({ message: 'Sucedio un error al intentar actualizar el chargue', error });
throw new InternalServerErrorException('Sucedio un error al actualizar el chargue');
Expand Down
4 changes: 2 additions & 2 deletions src/common/swagger/response/type.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class TypeResponse {
example: [
{
codType: 1,
typeDescription: 'MATUTINO',
description: 'MATUTINO',
backgroundColor: 'rgba(16,183,89, .25)',
borderColor: '#10b759',
start: '07:00:00',
Expand All @@ -16,7 +16,7 @@ export class TypeResponse {
},
{
codType: 2,
typeDescription: 'VESPERTINO',
description: 'VESPERTINO',
backgroundColor: 'rgba(253,126,20,.25)',
borderColor: '#fd7e14',
start: '14:00:00',
Expand Down
2 changes: 2 additions & 0 deletions src/common/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class Util {
}

static validateRegisterDate(schedule: Schedule): boolean {
//TODO Validate isPermissions

const dayOfWeek = Util.getDayOfWeek();

let validate: boolean[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/config/webAuthentication/webAuthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { User } from '../../user/entities/user.entity';
// Utilitarios de AuthnWeb

// Human-readable title for your website
const rpName = 'Sky Calendar App';
const rpName = 'Sky Krono App';
// A unique identifier for your website
const rpID = process.env.RP_ID;

Expand Down
1 change: 1 addition & 0 deletions src/licence/dto/create-licence.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateLicenceDto {}
4 changes: 4 additions & 0 deletions src/licence/dto/update-licence.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreateLicenceDto } from './create-licence.dto';

export class UpdateLicenceDto extends PartialType(CreateLicenceDto) {}
28 changes: 28 additions & 0 deletions src/licence/entities/licence.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IsNotEmpty } from 'class-validator';
import { Entity, Column, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { User } from '../../user/entities/user.entity';

@Entity()
export class Licence {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => User, (user) => user.id, {
nullable: false,
})
@JoinColumn({ name: 'codUser' })
@Column()
codUser: number;

@Column({ type: 'text', nullable: false })
@IsNotEmpty()
description: string;

@Column({ type: 'date', nullable: false })
@IsNotEmpty()
dateInit: Date;

@Column({ type: 'date', nullable: false })
@IsNotEmpty()
dateEnd: Date;
}
20 changes: 20 additions & 0 deletions src/licence/licence.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { LicenceController } from './licence.controller';
import { LicenceService } from './licence.service';

describe('LicenceController', () => {
let controller: LicenceController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [LicenceController],
providers: [LicenceService],
}).compile();

controller = module.get<LicenceController>(LicenceController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
34 changes: 34 additions & 0 deletions src/licence/licence.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { LicenceService } from './licence.service';
import { CreateLicenceDto } from './dto/create-licence.dto';
import { UpdateLicenceDto } from './dto/update-licence.dto';

@Controller('licence')
export class LicenceController {
constructor(private readonly licenceService: LicenceService) {}

@Post()
create(@Body() createLicenceDto: CreateLicenceDto) {
return this.licenceService.create(createLicenceDto);
}

@Get()
findAll() {
return this.licenceService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.licenceService.findOne(+id);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateLicenceDto: UpdateLicenceDto) {
return this.licenceService.update(+id, updateLicenceDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.licenceService.remove(+id);
}
}
13 changes: 13 additions & 0 deletions src/licence/licence.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { LicenceService } from './licence.service';
import { LicenceController } from './licence.controller';
import { Licence } from './entities/licence.entity';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
imports: [TypeOrmModule.forFeature([Licence])],
controllers: [LicenceController],
providers: [LicenceService],
exports: [LicenceService],
})
export class LicenceModule {}
18 changes: 18 additions & 0 deletions src/licence/licence.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { LicenceService } from './licence.service';

describe('LicenceService', () => {
let service: LicenceService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [LicenceService],
}).compile();

service = module.get<LicenceService>(LicenceService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
26 changes: 26 additions & 0 deletions src/licence/licence.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateLicenceDto } from './dto/create-licence.dto';
import { UpdateLicenceDto } from './dto/update-licence.dto';

@Injectable()
export class LicenceService {
create(createLicenceDto: CreateLicenceDto) {
return 'This action adds a new licence';
}

findAll() {
return `This action returns all licence`;
}

findOne(id: number) {
return `This action returns a #${id} licence`;
}

update(id: number, updateLicenceDto: UpdateLicenceDto) {
return `This action updates a #${id} licence`;
}

remove(id: number) {
return `This action removes a #${id} licence`;
}
}
5 changes: 2 additions & 3 deletions src/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ export class ScheduleService implements OnModuleInit {
return { message: Constant.MENSAJE_OK, info: 'Se actualizo exitosamente el Schedule' };
}
this.logger.warn(`Sucedio un error al actualizar el Schedule`);
return { message: 'Sucedio un error al actualizar el Schedule' };
throw new InternalServerErrorException('Sucedio un error al actualizar el Schedule');
} catch (error) {
this.logger.error(`Sucedio un error al intentar actualizar el Schedule`);
this.logger.error(error);
this.logger.error({ message: `Sucedio un error al intentar actualizar el Schedule`, error });
throw new InternalServerErrorException('Sucedio un error al actualizar el Schedule');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/task/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class TaskService {
return { message: Constant.MENSAJE_OK, info: 'Tarea eliminada exitosamente' };
}
this.logger.warn(`No se encontro tarea a eliminar`);
return { message: 'Sucedio un error', info: 'No se encontro tarea a eliminar' };
throw new InternalServerErrorException('Sucedio un error al eliminar la tarea');
} catch (error) {
this.logger.error(`Error al elimanar la tarea`, deleteTaskDto, error);
throw new InternalServerErrorException('Sucedio un error al eliminar la tarea');
Expand Down
30 changes: 29 additions & 1 deletion src/type/dto/create-type.dto.ts
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
export class CreateTypeDto {}
import { ApiProperty } from '@nestjs/swagger';
import { IsMilitaryTime, IsNotEmpty, IsString } from 'class-validator';

export class CreateTypeDto {
@ApiProperty()
@IsString()
@IsNotEmpty()
description: string;

@ApiProperty()
@IsString()
@IsNotEmpty()
backgroundColor: string;

@ApiProperty()
@IsString()
@IsNotEmpty()
borderColor: string;

@ApiProperty()
@IsMilitaryTime()
@IsNotEmpty()
start: Date;

@ApiProperty()
@IsMilitaryTime()
@IsNotEmpty()
end: Date;
}
9 changes: 7 additions & 2 deletions src/type/dto/update-type.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { PartialType } from '@nestjs/swagger';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';
import { CreateTypeDto } from './create-type.dto';

export class UpdateTypeDto extends PartialType(CreateTypeDto) {}
export class UpdateTypeDto extends PartialType(CreateTypeDto) {
@ApiProperty()
@IsNotEmpty()
codType: number;
}
2 changes: 1 addition & 1 deletion src/type/entities/type.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Type {

@Column({ type: 'varchar', length: 255, nullable: true })
@IsNotEmpty()
typeDescription: string;
description: string;

@Column({ type: 'varchar', length: 120 })
@IsNotEmpty()
Expand Down
4 changes: 2 additions & 2 deletions src/type/type.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('TypeController', () => {
const listaTypes: Type[] = [
{
codType: 1,
typeDescription: 'TEST',
description: 'TEST',
backgroundColor: '#ffff',
borderColor: '#ffff',
start: new Date(),
Expand All @@ -21,7 +21,7 @@ describe('TypeController', () => {
},
{
codType: 2,
typeDescription: 'TEST 2',
description: 'TEST 2',
backgroundColor: '#ffff',
borderColor: '#ffff',
start: new Date(),
Expand Down
Loading

0 comments on commit 7d37164

Please sign in to comment.