add folder operation and use createQueryRunner

This commit is contained in:
IO420
2025-09-16 22:37:25 -06:00
parent 7024bfdeac
commit 3e4b3b1b18
15 changed files with 150 additions and 76 deletions
+3 -2
View File
@@ -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;
}
+1 -1
View File
@@ -26,7 +26,7 @@ export class Student {
scale: 2,
default: 0.0,
})
credito: string;
credito: number;
@Column({
name: 'fecha_actualizacion_credito',
+1 -11
View File
@@ -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);
}
}
+16 -5
View File
@@ -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();
}
}