reinitializing codebase and resuming development
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { model, Schema, Types } from "mongoose";
|
||||
|
||||
const itemSchema = new Schema({
|
||||
product: {
|
||||
type: Types.ObjectId,
|
||||
required: true,
|
||||
ref: "product",
|
||||
},
|
||||
quantity: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
finalRate: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const remarksSchema = new Schema({
|
||||
createdOn: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
createdBy: {
|
||||
type: Types.ObjectId,
|
||||
required: true,
|
||||
ref: "user",
|
||||
},
|
||||
remarks: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ["REJECTION REASON", "CANCELLATION REASON", "OTHER"],
|
||||
},
|
||||
});
|
||||
|
||||
const schema = new Schema({
|
||||
createdBy: {
|
||||
type: Types.ObjectId,
|
||||
required: true,
|
||||
ref: "user",
|
||||
},
|
||||
createdOn: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
items: {
|
||||
type: [itemSchema],
|
||||
required: true,
|
||||
},
|
||||
totalValue: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: "CREATED",
|
||||
enum: ["CREATED", "CONFIRMED", "REJECTED", "CANCELLED", "COMPLETED"],
|
||||
},
|
||||
shippingAddress: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
remarks: {
|
||||
type: [remarksSchema],
|
||||
default: [],
|
||||
},
|
||||
});
|
||||
|
||||
export default model("enquiry", schema);
|
||||
@@ -0,0 +1,31 @@
|
||||
import Model from "./model.js";
|
||||
|
||||
// Create
|
||||
export const createEnquiry = async (data) => {
|
||||
return await Model.create(data);
|
||||
};
|
||||
|
||||
// Read (Get by ID)
|
||||
export const getEnquiryById = async (id) => {
|
||||
return await Model.findById(id);
|
||||
};
|
||||
|
||||
// Read (Get by Query)
|
||||
export const getEnquiryByQuery = async (query) => {
|
||||
return await Model.findOne(query);
|
||||
};
|
||||
|
||||
// Read (Get all)
|
||||
export const getAllEnquiries = async (query) => {
|
||||
return await Model.find(query);
|
||||
};
|
||||
|
||||
// Update
|
||||
export const updateEnquiry = async (id, data) => {
|
||||
return await Model.findByIdAndUpdate(id, data, { new: true });
|
||||
};
|
||||
|
||||
// Aggregate
|
||||
export const aggregateEnquiry = async (pipeline) => {
|
||||
return await Model.aggregate(pipeline);
|
||||
};
|
||||
Reference in New Issue
Block a user