location updates saved to db and base endpoints for other modules started

This commit is contained in:
Shibi Chakkaravarthy
2026-04-18 04:15:23 +05:30
parent 92769cfd38
commit eb84767d44
12 changed files with 167 additions and 44 deletions
-10
View File
@@ -1,10 +0,0 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({
createdOn: {
type: Date,
required: true
}
});
export default model("branch", schema);
+1 -1
View File
@@ -33,7 +33,7 @@ const schema = new Schema({
type: {
type: String,
required: true,
enum: ["HQ", "Branch", "Warehouse", "BackOffice"],
enum: ["HQ", "BRANCH", "WAREHOUSE"],
},
});
+2 -2
View File
@@ -7,7 +7,7 @@ export const createLocation = async (data) => {
return await Model.create({
...data,
coordinates: geoJson,
createdOn: dayjs().toISOString(),
createdOn: data?.recorded_at,
});
};
@@ -18,7 +18,7 @@ export const getLocationById = async (id) => {
// Read (Get by Query)
export const getLocationByQuery = async (query) => {
return await Model.findOne(query);
return await Model.findOne(query).sort({ createdOn: -1 });
};
// Read (Get by Radius)
+4
View File
@@ -13,6 +13,10 @@ const schema = new Schema({
type: String,
required: true,
},
email: {
type: String,
required: false,
},
state: {
type: String,
required: true,
+5
View File
@@ -25,6 +25,11 @@ const schema = new Schema({
type: Date,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
});
export default model("user", schema);
+18 -10
View File
@@ -15,6 +15,22 @@ const schema = new Schema({
type: Date,
required: true,
},
address: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
pincode: {
type: String,
required: true,
},
location: locationSchema,
category: {
type: String,
@@ -25,19 +41,11 @@ const schema = new Schema({
type: {
type: String,
required: true,
enum: [
"HQ",
"BRANCH",
"WAREHOUSE",
"VENDOR",
"PARTNER",
"DISTRIBUTOR",
"CLIENT",
],
enum: ["HQ", "BRANCH", "WAREHOUSE"],
},
entity: {
type: Types.ObjectId,
required: true,
required: false,
},
});
+3 -3
View File
@@ -13,11 +13,11 @@ export const getVenueById = async (id) => {
// Read (Get by Query)
export const getVenueByQuery = async (query) => {
return await Model.findOne(query);
}
};
// Read (Get all)
export const getAllVenues = async () => {
return await Model.find();
export const getAllVenues = async (query = {}) => {
return await Model.find(query);
};
// Update
+1
View File
@@ -19,3 +19,4 @@ export { default as Designation } from "./Designation/model";
export { default as Inventory } from "./Inventory/model";
export { default as InventoryLog } from "./InventoryLog/model";
export { default as Role } from "./Role/model";
export { default as Venue } from "./Venue/model";