feat: add assignedTo field to payments

This commit is contained in:
2025-11-18 14:03:22 +05:30
parent 8f5c0a1827
commit 2f46f46500
2 changed files with 23 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
import { buildJsonSchemas } from "fastify-zod"; import { buildJsonSchemas } from "fastify-zod";
import mongoose from "mongoose"; import mongoose, { Schema } from "mongoose";
import { pageQueryParams } from "../pagination"; import { pageQueryParams } from "../pagination";
const paymentSchema = new mongoose.Schema({ const paymentSchema = new mongoose.Schema({
@@ -27,6 +27,10 @@ const paymentSchema = new mongoose.Schema({
receiptNo: String, receiptNo: String,
fileId: String, fileId: String,
paymentDate: Date, paymentDate: Date,
assignedTo: {
type: [Schema.Types.ObjectId],
ref: "user",
},
}); });
export const paymentModel = mongoose.model("payment", paymentSchema); export const paymentModel = mongoose.model("payment", paymentSchema);

View File

@@ -57,6 +57,14 @@ export async function listPayments(
} }
pipeline.push( pipeline.push(
{
$lookup: {
from: "users",
localField: "assignedTo",
foreignField: "_id",
as: "assignedTo",
},
},
{ {
$project: { $project: {
_id: 1, _id: 1,
@@ -75,6 +83,16 @@ export async function listPayments(
receiptNo: 1, receiptNo: 1,
fileId: 1, fileId: 1,
paymentDate: 1, paymentDate: 1,
assignedTo: {
$let: {
vars: { assignedTo: { $arrayElemAt: ["$assignedTo", 0] } },
in: {
_id: "$$assignedTo._id",
pid: "$$assignedTo.pid",
name: "$$assignedTo.name",
},
},
},
}, },
}, },
{ {