Se guarda el id del usuario que creo el osp y el que lo actualice
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,
|
"when": 1770774052351,
|
||||||
"tag": "0017_mute_mole_man",
|
"tag": "0017_mute_mole_man",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 18,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1771855467870,
|
||||||
|
"tag": "0018_milky_prism",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -143,9 +143,13 @@ export const trainingSurveys = t.pgTable(
|
|||||||
familyBurden: t.integer('family_burden').notNull(),
|
familyBurden: t.integer('family_burden').notNull(),
|
||||||
numberOfChildren: t.integer('number_of_children').notNull(),
|
numberOfChildren: t.integer('number_of_children').notNull(),
|
||||||
generalObservations: t.text('general_observations'),
|
generalObservations: t.text('general_observations'),
|
||||||
|
// Fotos
|
||||||
photo1: t.text('photo1'),
|
photo1: t.text('photo1'),
|
||||||
photo2: t.text('photo2'),
|
photo2: t.text('photo2'),
|
||||||
photo3: t.text('photo3'),
|
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,
|
...timestamps,
|
||||||
},
|
},
|
||||||
(trainingSurveys) => ({
|
(trainingSurveys) => ({
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import {
|
|||||||
UploadedFiles,
|
UploadedFiles,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
StreamableFile,
|
StreamableFile,
|
||||||
Header
|
Header,
|
||||||
|
Req
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FilesInterceptor } from '@nestjs/platform-express';
|
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||||
import {
|
import {
|
||||||
@@ -94,10 +95,12 @@ export class TrainingController {
|
|||||||
description: 'Training record created successfully.',
|
description: 'Training record created successfully.',
|
||||||
})
|
})
|
||||||
async create(
|
async create(
|
||||||
|
@Req() req: Request,
|
||||||
@Body() createTrainingDto: CreateTrainingDto,
|
@Body() createTrainingDto: CreateTrainingDto,
|
||||||
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
@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 };
|
return { message: 'Training record created successfully', data };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,14 +114,17 @@ export class TrainingController {
|
|||||||
})
|
})
|
||||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||||
async update(
|
async update(
|
||||||
|
@Req() req: Request,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@Body() updateTrainingDto: UpdateTrainingDto,
|
@Body() updateTrainingDto: UpdateTrainingDto,
|
||||||
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
||||||
) {
|
) {
|
||||||
|
const userId = (req as any).user?.id;
|
||||||
const data = await this.trainingService.update(
|
const data = await this.trainingService.update(
|
||||||
+id,
|
+id,
|
||||||
updateTrainingDto,
|
updateTrainingDto,
|
||||||
files,
|
files,
|
||||||
|
userId,
|
||||||
);
|
);
|
||||||
return { message: 'Training record updated successfully', data };
|
return { message: 'Training record updated successfully', data };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,6 +265,7 @@ export class TrainingService {
|
|||||||
async create(
|
async create(
|
||||||
createTrainingDto: CreateTrainingDto,
|
createTrainingDto: CreateTrainingDto,
|
||||||
files: Express.Multer.File[],
|
files: Express.Multer.File[],
|
||||||
|
userId: number,
|
||||||
) {
|
) {
|
||||||
// 1. Guardar fotos
|
// 1. Guardar fotos
|
||||||
const photoPaths = await this.saveFiles(files);
|
const photoPaths = await this.saveFiles(files);
|
||||||
@@ -289,6 +290,8 @@ export class TrainingService {
|
|||||||
state: Number(state) ?? null,
|
state: Number(state) ?? null,
|
||||||
municipality: Number(municipality) ?? null,
|
municipality: Number(municipality) ?? null,
|
||||||
parish: Number(parish) ?? null,
|
parish: Number(parish) ?? null,
|
||||||
|
createdBy: userId,
|
||||||
|
updatedBy: userId,
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
@@ -299,6 +302,7 @@ export class TrainingService {
|
|||||||
id: number,
|
id: number,
|
||||||
updateTrainingDto: UpdateTrainingDto,
|
updateTrainingDto: UpdateTrainingDto,
|
||||||
files: Express.Multer.File[],
|
files: Express.Multer.File[],
|
||||||
|
userId: number,
|
||||||
) {
|
) {
|
||||||
const currentRecord = await this.findOne(id);
|
const currentRecord = await this.findOne(id);
|
||||||
|
|
||||||
@@ -334,6 +338,9 @@ export class TrainingService {
|
|||||||
updateData.visitDate = new Date(updateTrainingDto.visitDate);
|
updateData.visitDate = new Date(updateTrainingDto.visitDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// actualizamos el id del usuario que actualizo el registro
|
||||||
|
updateData.updatedBy = userId;
|
||||||
|
|
||||||
const [updatedRecord] = await this.drizzle
|
const [updatedRecord] = await this.drizzle
|
||||||
.update(trainingSurveys)
|
.update(trainingSurveys)
|
||||||
.set(updateData)
|
.set(updateData)
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ export const createTrainingAction = async (
|
|||||||
payloadToSend = rest as any;
|
payloadToSend = rest as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(payloadToSend);
|
// console.log(payloadToSend);
|
||||||
|
|
||||||
const [error, data] = await safeFetchApi(
|
const [error, data] = await safeFetchApi(
|
||||||
TrainingMutate,
|
TrainingMutate,
|
||||||
|
|||||||
Reference in New Issue
Block a user