Initialized Project with default middlewares and helpers, connected to Atlas Instance and created Swagger Setup. Created necessary DB models and authentication-authorization logic
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { model, Schema, Types } from "mongoose";
|
||||
|
||||
const coordinatesSchema = new Schema({
|
||||
latitude: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
longitude: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const schema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
city: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
state: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
pincode: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
createdBy: {
|
||||
type: Types.ObjectId,
|
||||
required: true,
|
||||
ref: "user",
|
||||
},
|
||||
createdOn: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
coordinates: {
|
||||
type: coordinatesSchema,
|
||||
required: true,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ["HQ", "Branch", "Warehouse", "BackOffice"],
|
||||
},
|
||||
});
|
||||
|
||||
export default model("branch", schema);
|
||||
@@ -0,0 +1,31 @@
|
||||
import Model from "./model.js";
|
||||
|
||||
// Create
|
||||
export const createBranch = async (data) => {
|
||||
return await Model.create(data);
|
||||
};
|
||||
|
||||
// Read (Get by ID)
|
||||
export const getBranchById = async (id) => {
|
||||
return await Model.findById(id);
|
||||
};
|
||||
|
||||
// Read (Get by Query)
|
||||
export const getBranchByQuery = async (query) => {
|
||||
return await Model.findOne(query);
|
||||
}
|
||||
|
||||
// Read (Get all)
|
||||
export const getAllBranches = async () => {
|
||||
return await Model.find();
|
||||
};
|
||||
|
||||
// Update
|
||||
export const updateBranch = async (id, data) => {
|
||||
return await Model.findByIdAndUpdate(id, data, { new: true });
|
||||
};
|
||||
|
||||
// Aggregate
|
||||
export const aggregateBranch = async (pipeline) => {
|
||||
return await Model.aggregate(pipeline);
|
||||
};
|
||||
Reference in New Issue
Block a user