update permits schema

This commit is contained in:
2025-02-05 09:57:08 +05:30
parent 9f337655a0
commit 8559aab3da
4 changed files with 160 additions and 14 deletions

View File

@@ -1,4 +1,3 @@
import mongoose from "mongoose";
import { orgModel } from "../organization/organization.schema";
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
import { userModel } from "../user/user.schema";
@@ -10,11 +9,25 @@ import {
UpdatePermitInput,
} from "./permit.schema";
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({
tenantId: tenantId,
tenantId: user.tenantId,
pid: generateId(),
createdAt: new Date(),
createdBy: user.userId,
...input,
});
@@ -92,6 +105,8 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
permitDate: 1,
stage: 1,
status: 1,
address: 1,
description: 1,
county: {
$let: {
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
@@ -168,12 +183,12 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
export async function updatePermit(
input: UpdatePermitInput,
permitId: string,
tenantId: string
user: AuthenticatedUser
) {
const updatePermitResult = await permitModel
.findOneAndUpdate(
{
$and: [{ tenantId: tenantId }, { pid: permitId }],
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
},
{ ...input, updatedAt: new Date() },
{ new: true }