feat(new): enforce social publishing governance
Amp-Thread-ID: https://ampcode.com/threads/T-019e55df-9bcd-73e6-9935-c1e6238cd273 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
1 parent
8a1389bcbc
commit
6d99f515c7
10 files changed
+643
-141
No files matched your search
@@ -12,6 +12,7 @@ export class ApprovalService {
|
||||
}
|
||||
|
||||
create(input: CreateApprovalInput): string {
|
||||
this.assertRequesterBelongsToOrg(input);
|
||||
const id = createId("app");
|
||||
const now = new Date().toISOString();
|
||||
this.db.prepare(`
|
||||
@@ -46,6 +47,7 @@ export class ApprovalService {
|
||||
}
|
||||
|
||||
decide(input: DecideApprovalInput): void {
|
||||
this.assertEmployee(input.orgId, input.decidedByEmployeeId, "Deciding employee was not found.");
|
||||
const now = new Date().toISOString();
|
||||
const result = this.db.prepare(`
|
||||
update approvals
|
||||
@@ -63,4 +65,26 @@ export class ApprovalService {
|
||||
payload: { decidedAt: now },
|
||||
});
|
||||
}
|
||||
|
||||
private assertRequesterBelongsToOrg(input: CreateApprovalInput): void {
|
||||
if (input.requestedByType === "employee") {
|
||||
if (!input.requestedById) throw new Error("Requesting employee is required.");
|
||||
this.assertEmployee(input.orgId, input.requestedById, "Requesting employee was not found.");
|
||||
return;
|
||||
}
|
||||
if (input.requestedByType === "agent") {
|
||||
if (!input.requestedById) throw new Error("Requesting agent is required.");
|
||||
const agent = this.db.prepare("select id from agents where id = ? and org_id = ?").get(input.requestedById, input.orgId);
|
||||
if (!agent) throw new Error("Requesting agent was not found.");
|
||||
return;
|
||||
}
|
||||
if (input.requestedByType === "system" && input.requestedById) {
|
||||
throw new Error("System approvals cannot include a requester id.");
|
||||
}
|
||||
}
|
||||
|
||||
private assertEmployee(orgId: string, employeeId: string, message: string): void {
|
||||
const employee = this.db.prepare("select id from employees where id = ? and org_id = ?").get(employeeId, orgId);
|
||||
if (!employee) throw new Error(message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user