add folder operation and use createQueryRunner
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDate, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
import { IsEmail, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateStudentDto {
|
||||
@IsNotEmpty()
|
||||
@@ -17,6 +17,7 @@ export class CreateStudentDto {
|
||||
@IsNumber()
|
||||
id_carrera: number;
|
||||
|
||||
@IsEmail()
|
||||
@IsString()
|
||||
correo: string;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Student {
|
||||
scale: 2,
|
||||
default: 0.0,
|
||||
})
|
||||
credito: string;
|
||||
credito: number;
|
||||
|
||||
@Column({
|
||||
name: 'fecha_actualizacion_credito',
|
||||
|
||||
@@ -27,17 +27,7 @@ export class StudentController {
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.studentService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto) {
|
||||
return this.studentService.update(+id, updateStudentDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.studentService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { UpdateStudentDto } from './dto/update-student.dto';
|
||||
import { Student } from './entities/student.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
@@ -31,11 +31,22 @@ export class StudentService {
|
||||
return student;
|
||||
}
|
||||
|
||||
update(id: number, updateStudentDto: UpdateStudentDto) {
|
||||
return `This action updates a #${id} student`;
|
||||
async GetCredit(id_cuenta: number): Promise<Student['credito']> {
|
||||
const student = await this.findOne(id_cuenta);
|
||||
return student.credito;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} student`;
|
||||
async UpdateCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
) {
|
||||
const repo = manager.getRepository(Student);
|
||||
return await repo
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({ credito: () => `credito - ${credit}` })
|
||||
.where({ id_cuenta })
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user