feat(f6.8): harden offline field flow and act documents
Android CI / RC / Android · lint, tests, debug APK, release compile (push) Successful in 3m41s
DH V2 CI / API · typecheck, tests, build (push) Successful in 31s
DH V2 CI / WEB · typecheck, build (push) Successful in 19s
Production dependency audit / API · production dependencies (push) Successful in 9s
Production dependency audit / WEB · production dependencies (push) Successful in 8s
DH V2 CI / Docker / scripts contract (push) Successful in 1m14s
Android CI / RC / Android · lint, tests, debug APK, release compile (push) Successful in 3m41s
DH V2 CI / API · typecheck, tests, build (push) Successful in 31s
DH V2 CI / WEB · typecheck, build (push) Successful in 19s
Production dependency audit / API · production dependencies (push) Successful in 9s
Production dependency audit / WEB · production dependencies (push) Successful in 8s
DH V2 CI / Docker / scripts contract (push) Successful in 1m14s
This commit is contained in:
@@ -278,6 +278,48 @@ export class InspectionActsService {
|
||||
return this.dataSource.transaction((manager) => this.loadView(manager, id));
|
||||
}
|
||||
|
||||
async listFieldMedia(id: string) {
|
||||
const [act] = await this.dataSource.query(
|
||||
'SELECT id FROM inspection_acts WHERE id=$1::uuid',
|
||||
[id],
|
||||
) as Array<{ id: string }>;
|
||||
if (!act) throw actNotFound();
|
||||
const data = await this.dataSource.query(`
|
||||
SELECT
|
||||
media.id,
|
||||
media.asset_id AS "assetId",
|
||||
asset.code AS "assetCode",
|
||||
asset.name AS "assetName",
|
||||
media.kind,
|
||||
media.original_name AS "originalName",
|
||||
media.mime_type AS "mimeType",
|
||||
media.size_bytes::double precision AS "sizeBytes",
|
||||
media.sha256,
|
||||
media.title,
|
||||
media.description,
|
||||
media.captured_at AS "capturedAt",
|
||||
media.latitude::double precision AS latitude,
|
||||
media.longitude::double precision AS longitude,
|
||||
media.accuracy_m::double precision AS "accuracyM",
|
||||
media.source,
|
||||
capture.device_captured_at AS "fieldCapturedAt",
|
||||
capture.created_at AS "createdAt"
|
||||
FROM inspection_acts act
|
||||
INNER JOIN inspection_act_assets link
|
||||
ON link.act_id=act.id AND link.included=true
|
||||
INNER JOIN asset_field_capture_events capture
|
||||
ON capture.visit_id=act.visit_id
|
||||
AND capture.asset_id=link.asset_id
|
||||
AND capture.event_type='PHOTO'
|
||||
INNER JOIN asset_media media
|
||||
ON media.id=capture.media_id AND media.deleted_at IS NULL
|
||||
INNER JOIN assets asset ON asset.id=media.asset_id
|
||||
WHERE act.id=$1::uuid
|
||||
ORDER BY capture.device_captured_at DESC,capture.created_at DESC,media.id
|
||||
`, [id]);
|
||||
return { data };
|
||||
}
|
||||
|
||||
async create(
|
||||
visitId: string,
|
||||
dto: CreateInspectionActDto,
|
||||
@@ -289,6 +331,22 @@ export class InspectionActsService {
|
||||
const visit = await this.lockVisit(manager, visitId);
|
||||
this.assertVisitOpen(visit);
|
||||
await this.assertActorAssigned(manager, visitId, principal);
|
||||
if (dto.clientGeneratedId) {
|
||||
const [existing] = await manager.query(`
|
||||
SELECT id, visit_id AS "visitId"
|
||||
FROM inspection_acts
|
||||
WHERE id=$1
|
||||
`, [dto.clientGeneratedId]) as Array<{ id: string; visitId: string }>;
|
||||
if (existing) {
|
||||
if (existing.visitId !== visitId) {
|
||||
throw new ConflictException({
|
||||
code: 'INSPECTION_ACT_CLIENT_ID_REUSED',
|
||||
message: 'El identificador offline del Acta ya fue utilizado en otra inspección',
|
||||
});
|
||||
}
|
||||
return this.loadView(manager, existing.id);
|
||||
}
|
||||
}
|
||||
await this.assertVisitHasNoDraftAct(manager, visitId);
|
||||
await this.assertVisitAssets(manager, visitId, dto.assetIds);
|
||||
const occurredAt = new Date(dto.occurredAt);
|
||||
@@ -305,6 +363,7 @@ export class InspectionActsService {
|
||||
`, [occurredAt])) as Array<{ date_part: string }>;
|
||||
const code = `ACT-${String(actNumber).padStart(5, '0')}-${dateRow.date_part}`;
|
||||
const act = manager.getRepository(InspectionAct).create({
|
||||
id: dto.clientGeneratedId,
|
||||
visitId,
|
||||
actYear,
|
||||
actNumber,
|
||||
|
||||
Reference in New Issue
Block a user