Merge branch 'main' of https://git.fondemi.gob.ve/Fondemi/sistema_base
cambios en como se guardan los datos
This commit is contained in:
4
apps/api/src/database/migrations/0018_milky_prism.sql
Normal file
4
apps/api/src/database/migrations/0018_milky_prism.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE "training_surveys" ADD COLUMN "created_by" integer;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ADD COLUMN "updated_by" integer;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ADD CONSTRAINT "training_surveys_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "training_surveys" ADD CONSTRAINT "training_surveys_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "auth"."users"("id") ON DELETE cascade ON UPDATE no action;
|
||||
2046
apps/api/src/database/migrations/meta/0018_snapshot.json
Normal file
2046
apps/api/src/database/migrations/meta/0018_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -127,6 +127,13 @@
|
||||
"when": 1770774052351,
|
||||
"tag": "0017_mute_mole_man",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 18,
|
||||
"version": "7",
|
||||
"when": 1771855467870,
|
||||
"tag": "0018_milky_prism",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -135,9 +135,13 @@ export const trainingSurveys = t.pgTable(
|
||||
familyBurden: t.integer('family_burden').notNull(),
|
||||
numberOfChildren: t.integer('number_of_children').notNull(),
|
||||
generalObservations: t.text('general_observations'),
|
||||
// Fotos
|
||||
photo1: t.text('photo1'),
|
||||
photo2: t.text('photo2'),
|
||||
photo3: t.text('photo3'),
|
||||
// informacion del usuario que creo y actualizo el registro
|
||||
createdBy: t.integer('created_by').references(() => users.id, { onDelete: 'cascade' }),
|
||||
updatedBy: t.integer('updated_by').references(() => users.id, { onDelete: 'cascade' }),
|
||||
...timestamps,
|
||||
},
|
||||
(trainingSurveys) => ({
|
||||
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
UploadedFiles,
|
||||
UseInterceptors,
|
||||
StreamableFile,
|
||||
Header
|
||||
Header,
|
||||
Req
|
||||
} from '@nestjs/common';
|
||||
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||
import {
|
||||
@@ -94,10 +95,12 @@ export class TrainingController {
|
||||
description: 'Training record created successfully.',
|
||||
})
|
||||
async create(
|
||||
@Req() req: Request,
|
||||
@Body() createTrainingDto: CreateTrainingDto,
|
||||
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
||||
) {
|
||||
const data = await this.trainingService.create(createTrainingDto, files);
|
||||
const userId = (req as any).user?.id;
|
||||
const data = await this.trainingService.create(createTrainingDto, files, userId);
|
||||
return { message: 'Training record created successfully', data };
|
||||
}
|
||||
|
||||
@@ -111,14 +114,17 @@ export class TrainingController {
|
||||
})
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async update(
|
||||
@Req() req: Request,
|
||||
@Param('id') id: string,
|
||||
@Body() updateTrainingDto: UpdateTrainingDto,
|
||||
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
||||
) {
|
||||
const userId = (req as any).user?.id;
|
||||
const data = await this.trainingService.update(
|
||||
+id,
|
||||
updateTrainingDto,
|
||||
files,
|
||||
userId,
|
||||
);
|
||||
return { message: 'Training record updated successfully', data };
|
||||
}
|
||||
|
||||
@@ -265,6 +265,7 @@ export class TrainingService {
|
||||
async create(
|
||||
createTrainingDto: CreateTrainingDto,
|
||||
files: Express.Multer.File[],
|
||||
userId: number,
|
||||
) {
|
||||
// 1. Guardar fotos
|
||||
const photoPaths = await this.saveFiles(files);
|
||||
@@ -288,7 +289,9 @@ export class TrainingService {
|
||||
photo3: photoPaths[2] ?? null,
|
||||
state: Number(state) ?? null,
|
||||
municipality: Number(municipality) ?? null,
|
||||
parish: Number(parish) ?? null,
|
||||
parish: Number(parish) ?? null,
|
||||
createdBy: userId,
|
||||
updatedBy: userId,
|
||||
})
|
||||
.returning();
|
||||
|
||||
@@ -299,6 +302,7 @@ export class TrainingService {
|
||||
id: number,
|
||||
updateTrainingDto: UpdateTrainingDto,
|
||||
files: Express.Multer.File[],
|
||||
userId: number,
|
||||
) {
|
||||
const currentRecord = await this.findOne(id);
|
||||
|
||||
@@ -334,6 +338,9 @@ export class TrainingService {
|
||||
updateData.visitDate = new Date(updateTrainingDto.visitDate);
|
||||
}
|
||||
|
||||
// actualizamos el id del usuario que actualizo el registro
|
||||
updateData.updatedBy = userId;
|
||||
|
||||
const [updatedRecord] = await this.drizzle
|
||||
.update(trainingSurveys)
|
||||
.set(updateData)
|
||||
|
||||
@@ -90,7 +90,7 @@ export const createTrainingAction = async (
|
||||
payloadToSend = rest as any;
|
||||
}
|
||||
|
||||
console.log(payloadToSend);
|
||||
// console.log(payloadToSend);
|
||||
|
||||
const [error, data] = await safeFetchApi(
|
||||
TrainingMutate,
|
||||
|
||||
Reference in New Issue
Block a user