feat: add assignedTo field to payments
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import mongoose, { Schema } from "mongoose";
|
||||
import { pageQueryParams } from "../pagination";
|
||||
|
||||
const paymentSchema = new mongoose.Schema({
|
||||
@@ -27,6 +27,10 @@ const paymentSchema = new mongoose.Schema({
|
||||
receiptNo: String,
|
||||
fileId: String,
|
||||
paymentDate: Date,
|
||||
assignedTo: {
|
||||
type: [Schema.Types.ObjectId],
|
||||
ref: "user",
|
||||
},
|
||||
});
|
||||
|
||||
export const paymentModel = mongoose.model("payment", paymentSchema);
|
||||
|
||||
@@ -57,6 +57,14 @@ export async function listPayments(
|
||||
}
|
||||
|
||||
pipeline.push(
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "assignedTo",
|
||||
foreignField: "_id",
|
||||
as: "assignedTo",
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
@@ -75,6 +83,16 @@ export async function listPayments(
|
||||
receiptNo: 1,
|
||||
fileId: 1,
|
||||
paymentDate: 1,
|
||||
assignedTo: {
|
||||
$let: {
|
||||
vars: { assignedTo: { $arrayElemAt: ["$assignedTo", 0] } },
|
||||
in: {
|
||||
_id: "$$assignedTo._id",
|
||||
pid: "$$assignedTo.pid",
|
||||
name: "$$assignedTo.name",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user