feat(renovaciones): send renewal notices from the list, drop manual marking
The Pólizas tab now sends. Each pending row gets an "Enviar aviso" button backed by POST /renewals/send, which renders, mails and records the notice through the same path the daily sweep uses — so a hand-sent letter is marked exactly like a swept one and drops off the pending list. Sending is now the only way a notice gets marked as sent. Remove the manual "Marcar impreso" / "Marcar EMAIL" buttons and the endpoint behind them (POST /policies/:id/renewal-notices, PoliciesService.markRenewalNotice, MarkRenewalNoticeDto): they wrote a sentAt with no mail behind it, which let the list claim a customer was notified when nothing was sent. sendOne refuses a generation that already has a sentAt (409) so a double click cannot mail the customer twice, and 400s when the customer has no email on file. Sweep and single send share the new deliver() helper.
This commit is contained in:
@@ -6,7 +6,6 @@ import { StorageService } from "../storage/storage.service";
|
||||
import { extForUpload, type UploadedFileLike } from "../storage/upload-file";
|
||||
import { toDate } from "../common/coerce";
|
||||
import { CreatePolicyDto, UpdatePolicyDto } from "./policy.dto";
|
||||
import { MarkRenewalNoticeDto } from "./renewal-notice.dto";
|
||||
import {
|
||||
BeneficiaryDto,
|
||||
ClaimDto,
|
||||
@@ -359,33 +358,6 @@ export class PoliciesService {
|
||||
return this.prisma.policy.update({ where: { id }, data: { archivedAt: null } });
|
||||
}
|
||||
|
||||
async markRenewalNotice(
|
||||
policyId: string,
|
||||
dto: MarkRenewalNoticeDto,
|
||||
sentById: string,
|
||||
) {
|
||||
await this.ensurePolicy(policyId);
|
||||
const sentAt = toDate(dto.sentAt) ?? new Date();
|
||||
return this.prisma.renewalNotice.upsert({
|
||||
where: {
|
||||
policyId_generation: { policyId, generation: dto.generation },
|
||||
},
|
||||
create: {
|
||||
policyId,
|
||||
generation: dto.generation,
|
||||
channel: dto.channel,
|
||||
sentAt,
|
||||
sentById,
|
||||
notes: dto.notes,
|
||||
},
|
||||
update: {
|
||||
channel: dto.channel,
|
||||
sentAt,
|
||||
sentById,
|
||||
notes: dto.notes,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async ensurePolicy(id: string) {
|
||||
const found = await this.prisma.policy.findUnique({
|
||||
|
||||
Reference in New Issue
Block a user