mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-07 11:16:37 +00:00
♻️ set approval & blocked work in tandem
This commit is contained in:
@@ -22,7 +22,7 @@ import { approvals, clients, db, orgs, type Approval } from "@server/db";
|
|||||||
import { getOrgTierData } from "@server/lib/billing";
|
import { getOrgTierData } from "@server/lib/billing";
|
||||||
import { TierId } from "@server/lib/billing/tiers";
|
import { TierId } from "@server/lib/billing/tiers";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq, type InferInsertModel } from "drizzle-orm";
|
||||||
import type { NextFunction, Request, Response } from "express";
|
import type { NextFunction, Request, Response } from "express";
|
||||||
|
|
||||||
const paramsSchema = z.strictObject({
|
const paramsSchema = z.strictObject({
|
||||||
@@ -112,12 +112,17 @@ export async function processPendingApproval(
|
|||||||
updatedApproval.type === "user_device" &&
|
updatedApproval.type === "user_device" &&
|
||||||
updatedApproval.clientId
|
updatedApproval.clientId
|
||||||
) {
|
) {
|
||||||
|
const updateDataBody: Partial<InferInsertModel<typeof clients>> = {
|
||||||
|
approvalState: updateData.decision
|
||||||
|
};
|
||||||
|
|
||||||
|
if (updateData.decision === "denied") {
|
||||||
|
updateDataBody.blocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(clients)
|
.update(clients)
|
||||||
.set({
|
.set(updateDataBody)
|
||||||
approvalState: updateData.decision,
|
|
||||||
blocked: updateData.decision == "denied"
|
|
||||||
})
|
|
||||||
.where(eq(clients.clientId, updatedApproval.clientId));
|
.where(eq(clients.clientId, updatedApproval.clientId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export async function unblockClient(
|
|||||||
// Unblock the client
|
// Unblock the client
|
||||||
await db
|
await db
|
||||||
.update(clients)
|
.update(clients)
|
||||||
.set({ blocked: false })
|
.set({ blocked: false, approvalState: null })
|
||||||
.where(eq(clients.clientId, clientId));
|
.where(eq(clients.clientId, clientId));
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
|
|||||||
Reference in New Issue
Block a user