update permits schema
This commit is contained in:
@@ -18,7 +18,7 @@ export async function createPermitHandler(
|
|||||||
const input = req.body as CreatePermitInput;
|
const input = req.body as CreatePermitInput;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const permit = await createPermit(input, req.user.tenantId);
|
const permit = await createPermit(input, req.user);
|
||||||
return res.code(201).send(permit);
|
return res.code(201).send(permit);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -62,11 +62,7 @@ export async function updatePermitHandler(
|
|||||||
const { permitId } = req.params as { permitId: string };
|
const { permitId } = req.params as { permitId: string };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedPermit = await updatePermit(
|
const updatedPermit = await updatePermit(input, permitId, req.user);
|
||||||
input,
|
|
||||||
permitId,
|
|
||||||
req.user.tenantId
|
|
||||||
);
|
|
||||||
if (!updatedPermit)
|
if (!updatedPermit)
|
||||||
return res.code(404).send({ error: "resource not found" });
|
return res.code(404).send({ error: "resource not found" });
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,13 @@ const permitSchema = new mongoose.Schema({
|
|||||||
ref: "organization",
|
ref: "organization",
|
||||||
},
|
},
|
||||||
permitDate: Date,
|
permitDate: Date,
|
||||||
stage: String,
|
stage: new mongoose.Schema(
|
||||||
|
{
|
||||||
|
pipeline: Array,
|
||||||
|
currentStage: Number,
|
||||||
|
},
|
||||||
|
{ _id: false }
|
||||||
|
),
|
||||||
status: String,
|
status: String,
|
||||||
assignedTo: {
|
assignedTo: {
|
||||||
type: mongoose.Types.ObjectId,
|
type: mongoose.Types.ObjectId,
|
||||||
@@ -59,7 +65,19 @@ const permitCore = {
|
|||||||
county: z.string().optional(),
|
county: z.string().optional(),
|
||||||
client: z.string().optional(),
|
client: z.string().optional(),
|
||||||
permitDate: z.date(),
|
permitDate: z.date(),
|
||||||
stage: z.string().optional(),
|
stage: z
|
||||||
|
.object({
|
||||||
|
pipeline: z.array(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
date: z.date().nullable().optional(),
|
||||||
|
description: z.string().optional(),
|
||||||
|
comment: z.string().optional(),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
currentStage: z.number(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
status: z.string().optional(),
|
status: z.string().optional(),
|
||||||
assignedTo: z.string().optional(),
|
assignedTo: z.string().optional(),
|
||||||
};
|
};
|
||||||
@@ -105,7 +123,21 @@ const updatePermitInput = z.object({
|
|||||||
county: z.string().optional(),
|
county: z.string().optional(),
|
||||||
client: z.string().optional(),
|
client: z.string().optional(),
|
||||||
permitDate: z.date().optional(),
|
permitDate: z.date().optional(),
|
||||||
stage: z.string().optional(),
|
stage: z
|
||||||
|
.object({
|
||||||
|
pipeline: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
date: z.date().nullable().optional(),
|
||||||
|
description: z.string().optional(),
|
||||||
|
comment: z.string().optional(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
currentStage: z.number().optional(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
status: z.string().optional(),
|
status: z.string().optional(),
|
||||||
assignedTo: z.string().optional(),
|
assignedTo: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import mongoose from "mongoose";
|
|
||||||
import { orgModel } from "../organization/organization.schema";
|
import { orgModel } from "../organization/organization.schema";
|
||||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||||
import { userModel } from "../user/user.schema";
|
import { userModel } from "../user/user.schema";
|
||||||
@@ -10,11 +9,25 @@ import {
|
|||||||
UpdatePermitInput,
|
UpdatePermitInput,
|
||||||
} from "./permit.schema";
|
} from "./permit.schema";
|
||||||
import { ChangeEvent, dbEvents } from "../realtime";
|
import { ChangeEvent, dbEvents } from "../realtime";
|
||||||
|
import { pipeline } from "../utils/pipeline";
|
||||||
|
import { AuthenticatedUser } from "../auth";
|
||||||
|
|
||||||
|
export async function createPermit(
|
||||||
|
input: CreatePermitInput,
|
||||||
|
user: AuthenticatedUser
|
||||||
|
) {
|
||||||
|
if (!input.stage) {
|
||||||
|
input.stage = {
|
||||||
|
pipeline: pipeline,
|
||||||
|
currentStage: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function createPermit(input: CreatePermitInput, tenantId: string) {
|
|
||||||
const permit = await permitModel.create({
|
const permit = await permitModel.create({
|
||||||
tenantId: tenantId,
|
tenantId: user.tenantId,
|
||||||
pid: generateId(),
|
pid: generateId(),
|
||||||
|
createdAt: new Date(),
|
||||||
|
createdBy: user.userId,
|
||||||
...input,
|
...input,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,6 +105,8 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
|
|||||||
permitDate: 1,
|
permitDate: 1,
|
||||||
stage: 1,
|
stage: 1,
|
||||||
status: 1,
|
status: 1,
|
||||||
|
address: 1,
|
||||||
|
description: 1,
|
||||||
county: {
|
county: {
|
||||||
$let: {
|
$let: {
|
||||||
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
|
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
|
||||||
@@ -168,12 +183,12 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
|
|||||||
export async function updatePermit(
|
export async function updatePermit(
|
||||||
input: UpdatePermitInput,
|
input: UpdatePermitInput,
|
||||||
permitId: string,
|
permitId: string,
|
||||||
tenantId: string
|
user: AuthenticatedUser
|
||||||
) {
|
) {
|
||||||
const updatePermitResult = await permitModel
|
const updatePermitResult = await permitModel
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
$and: [{ tenantId: tenantId }, { pid: permitId }],
|
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
||||||
},
|
},
|
||||||
{ ...input, updatedAt: new Date() },
|
{ ...input, updatedAt: new Date() },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
|
|||||||
103
src/utils/pipeline.ts
Normal file
103
src/utils/pipeline.ts
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
export const pipeline: {
|
||||||
|
name: string;
|
||||||
|
date?: Date;
|
||||||
|
description?: string;
|
||||||
|
comment?: string;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
name: "Ready to submit",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Validating",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Information Required",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "In Progress",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "On Hold",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Submitted",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "In Review",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Awaiting Client Reply",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Fees Due",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Revision Request",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ready to Issue",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Issued",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Completed",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invoiced",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Cancel/Void",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Expired",
|
||||||
|
date: null,
|
||||||
|
description: "",
|
||||||
|
comment: "",
|
||||||
|
},
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user