This commit is contained in:
mark H 2024-09-24 09:03:35 +08:00
parent c6b13812fe
commit 57ba9ee775
14 changed files with 974 additions and 422 deletions

View File

@ -1,114 +0,0 @@
import Collection from "../models/Collection.js";
export const createCollection = async (req, res, next) => {
const newCollection = new Collection({
name: req.body.name,
created_by: req.body.created_by,
header: req.body.header,
});
console.log(req.body);
try {
const savedCollection = await newCollection.save();
res.status(200).json(savedCollection);
console.log(savedCollection);
} catch (err) {
// console.log(req.body);
res.status(400).json({ message: err.message });
next(err);
}
};
export const updateCollection = async (req, res, next) => {
try {
console.log(req.params.id);
const updatedCollection = await Collection.findByIdAndUpdate(
req.params.id,
{ $set: req.body },
{ new: true }
);
if (updatedCollection) {
res.status(200).json(updatedCollection);
} else {
res.status(200).json("Collection does not exist.");
}
} catch (err) {
next(err);
}
};
export const updateCollectionByEndpoint = async (req, res, next) => {
try {
const { id, endpoint_id } = req.params;
const updatedCollection = await Collection.findByIdAndUpdate(
req.params.id,
{ $push: { endpoints: req.body.endpoint_id } },
{ new: true }
);
if (updatedCollection) {
console.log("Updated Collection:", endpoint_id);
res.status(200).json(updatedCollection);
} else {
res.status(404).json({ endpoint: "Collection or endpoint not found." });
}
} catch (err) {
next(err);
}
};
export const deleteCollection = async (req, res, next) => {
try {
const getCollection = await Collection.findByIdAndDelete(req.params.id);
if (getCollection) {
res.status(200).json("Collection has been deleted.");
} else {
res.status(404).json("Collection does not exist.");
}
} catch (err) {
res.status(404).json({ message: err.message });
next(err);
}
};
export const getCollections = async (req, res, next) => {
try {
const getCollection = await Collection.find()
.populate({
path: "endpoints",
model: "Endpoint",
})
.exec();
// const Collection = getCollection.reverse();
if (getCollection) {
res.status(200).json(getCollection);
} else {
res.status(404).json("Collection does not exist.");
}
} catch (err) {
res.status(404).json({ message: err.message });
next(err);
}
};
export const getCollection = async (req, res, next) => {
try {
const foundCollection = await Collection.findById(req.params.id)
.populate({
path: "endpoints",
model: "Endpoint",
})
.exec();
if (foundCollection) {
res.status(200).json(foundCollection);
} else {
res.status(404).json("Collection does not exist.");
}
} catch (err) {
res.status(500).json({ message: err.message });
next(err);
}
};

View File

@ -1,96 +0,0 @@
import Endpoint from "../models/Endpoint.js";
export const createEndpoint = async (req, res, next) => {
const newEndpoint = new Endpoint({
name: req.body.name,
endpoint: req.body.endpoint,
method: req.body.method,
collection_id: req.body.collection_id,
created_by: req.body.created_by,
body_json: req.body.body_json,
form_data: req.body.form_data,
header: req.body.header,
params: req.body.params,
});
console.log(req.body);
try {
const savedEndpoint = await newEndpoint.save();
res.status(200).json(savedEndpoint);
console.log(savedEndpoint);
} catch (err) {
// console.log(req.body);
res.status(400).json({ message: err.message });
next(err);
}
};
export const updateEndpoint = async (req, res, next) => {
try {
console.log(req.params.id);
const updatedEndpoint = await Endpoint.findByIdAndUpdate(
req.params.id,
{ $set: req.body },
{ new: true }
);
if (updatedEndpoint) {
res.status(200).json(updatedEndpoint);
} else {
res.status(200).json("Endpoint does not exist.");
}
} catch (err) {
next(err);
}
};
export const deleteEndpoint = async (req, res, next) => {
try {
const getEndpoint = await Endpoint.findByIdAndDelete(req.params.id);
if (getEndpoint) {
res.status(200).json("Endpoint has been deleted.");
} else {
res.status(404).json("Endpoint does not exist.");
}
} catch (err) {
res.status(404).json({ message: err.message });
next(err);
}
};
export const getEndpoints = async (req, res, next) => {
try {
const getEndpoint = await Endpoint.find();
// const Endpoint = getEndpoint.reverse();
if (getEndpoint) {
res.status(200).json(getEndpoint);
} else {
res.status(404).json("Endpoint does not exist.");
}
} catch (err) {
res.status(404).json({ message: err.message });
next(err);
}
};
export const getEndpoint = async (req, res, next) => {
try {
const foundEndpoint = await Endpoint.findById(req.params.id)
.populate({
path: "userRef",
model: "User",
// select: "fName lName username photo",
})
.exec();
if (foundEndpoint) {
res.status(200).json(foundEndpoint);
} else {
res.status(404).json("Endpoint does not exist.");
}
} catch (err) {
res.status(500).json({ message: err.message });
next(err);
}
};

105
controllers/kds.js Normal file
View File

@ -0,0 +1,105 @@
import KDSModel from "../models/KDS.js";
// Resolver to create a new KDS document
export const createKDS = async (req, res) => {
try {
const kdsData = req.body;
const { ref_id } = kdsData;
// Check if a KDS document with the same ref_id already exists
const existingKDS = await KDSModel.findOne({ ref_id });
if (existingKDS) {
return res.status(400).json({ error: `KDS with ref_id ${ref_id} already exists.` });
}
// Proceed to create the new KDS document if ref_id is unique
const newKDS = new KDSModel(kdsData);
await newKDS.save();
res.status(201).json(newKDS);
} catch (error) {
res.status(400).json({ error: `Failed to create KDS document: ${error.message}` });
}
};
// Resolver to get all KDS documents
export const getAllKDS = async (req, res) => {
try {
const kdsList = await KDSModel.find();
res.status(200).json(kdsList);
} catch (error) {
res.status(500).json({ error: "Failed to retrieve KDS documents" });
}
};
export const getKDS = async (req, res, next) => {
try {
const foundKDS = await KDSModel.findById(req.params.id)
.populate({
path: "userRef",
model: "User",
// select: "fName lName username photo",
})
.exec();
if (foundKDS) {
res.status(200).json(foundKDS);
} else {
res.status(404).json("KDS does not exist.");
}
} catch (err) {
res.status(500).json({ message: err.message });
next(err);
}
};
export const updateKDS = async (req, res, next) => {
try {
console.log(req.params.id);
const updatedKDS = await KDSModel.findByIdAndUpdate(
req.params.id,
{ $set: req.body },
{ new: true }
);
if (updatedKDS) {
res.status(200).json(updatedKDS);
} else {
res.status(404).json("KDS does not exist.");
}
} catch (err) {
next(err);
}
};
export const updateKDSrow = async (req, res, next) => {
try {
console.log(req.params.id);
const updatedKDS = await KDSModel.findByIdAndUpdate(
req.params.id,
{ $set: req.body },
{ new: true }
);
if (updatedKDS) {
res.status(200).json(updatedKDS);
} else {
res.status(404).json("KDS does not exist.");
}
} catch (err) {
next(err);
}
};
export const deleteKDS = async (req, res, next) => {
try {
const getKDS = await KDSModel.findByIdAndDelete(req.params.id);
if (getKDS) {
res.status(200).json("KDS has been deleted.");
} else {
res.status(404).json("KDS does not exist.");
}
} catch (err) {
res.status(404).json({ message: err.message });
next(err);
}
};

656
index.js
View File

@ -10,8 +10,9 @@ import path from "path";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
import authRoutes from "./routes/auth.js"; import authRoutes from "./routes/auth.js";
import userRoutes from "./routes/users.js"; import userRoutes from "./routes/users.js";
import collectionRoutes from "./routes/collection.js"; import kdsRoutes from "./routes/kds.js";
import endpointRoutes from "./routes/endpoint.js";
import Odoo from "odoo-xmlrpc";
// import webemailRoutes from "./routes/webemail.js"; // import webemailRoutes from "./routes/webemail.js";
import axios from "axios"; import axios from "axios";
@ -71,8 +72,7 @@ const upload = multer({ storage });
/* ROUTES */ /* ROUTES */
app.use("/api/auth", authRoutes); app.use("/api/auth", authRoutes);
app.use("/api/users", userRoutes); app.use("/api/users", userRoutes);
app.use("/api/collections", collectionRoutes); app.use("/api/kds", kdsRoutes);
app.use("/api/endpoints", endpointRoutes);
// app.use("/api/web-emails", webemailRoutes); // app.use("/api/web-emails", webemailRoutes);
app.post("/api/upload_images", upload.single("image"), async (req, res) => { app.post("/api/upload_images", upload.single("image"), async (req, res) => {
@ -88,7 +88,7 @@ app.post("/api/upload_images", upload.single("image"), async (req, res) => {
}); });
function sendEmail(req, res, next) { function sendEmail(req, res, next) {
const apiKey = const apiKey =
"ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q="; // Replace with your Mailjet API key "ODA4MDc4ZThjMDA4NjVhYzU4MTcyNDJjNTMxY2JlZGU6MGQ4ODg3ZTdiZjY1ZWNkMmQ0NzdiOWJhZGIyYTJhY2Q=";
const apiUrl = "https://api.mailjet.com/v3.1/send"; const apiUrl = "https://api.mailjet.com/v3.1/send";
// const otp = generateOTP(6); // You should have a function to generate the OTP // const otp = generateOTP(6); // You should have a function to generate the OTP
@ -142,8 +142,652 @@ function sendEmail(req, res, next) {
}); });
} }
app.post("/api/send-email/", sendEmail); app.post("/api/send-email/", sendEmail);
const odooClient = new Odoo({
url: "https://gis.pivi.com.ph",
db: "gis.pivi.com.ph",
username: "egalang@obanana.com",
password: "P@$$w0rd!",
});
const odooClient2 = new Odoo({
url: "http://localhost:8069/",
db: "Paymongo",
username: "mahipe@obanana.com",
password: "abcd123",
});
app.get("/get-assets", async (req, res) => {
try {
odooClient.connect(async function (err) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Connection Error: " + err.message });
}
console.log("Connected to Odoo server.");
// Fetch asset IDs
const inParams = [];
inParams.push([["name", "!=", false]]);
inParams.push(parseInt(req.query.offset) || 0); //offset
inParams.push(parseInt(req.query.limit) || 0); //Limit
const params = [inParams];
const assets = [];
let recordsArray = [];
let attributes = [];
let bounds = [];
let images = [];
odooClient.execute_kw(
"pivi_assets.pivi_assets",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Search Error: " + err.message });
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
const paramsRead = [inParamsRead];
odooClient.execute_kw(
"pivi_assets.pivi_assets",
"read",
paramsRead,
async function (err2, records) {
if (err2) {
console.log(err2);
return res
.status(500)
.json({ error: "Read Error: " + err2.message });
} else {
recordsArray = records;
odooClient.execute_kw(
"pivi_assets.attributes",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Search Error: " + err.message });
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
inParamsRead.push([
"id",
"name",
"value",
"asset",
"__last_update",
"display_name",
"create_uid",
"create_date",
"write_uid",
"write_date",
]);
const paramsRead = [inParamsRead];
odooClient.execute_kw(
"pivi_assets.attributes",
"read",
paramsRead,
async function (err2, attr) {
if (err2) {
console.log(err2);
return res
.status(500)
.json({ error: "Read Error: " + err2.message });
} else {
attributes = attr;
odooClient.execute_kw(
"pivi_assets.bounds",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res.status(500).json({
error: "Search Error: " + err.message,
});
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
inParamsRead.push([
"id",
"name",
"longitude",
"latitude",
"asset",
"__last_update",
"display_name",
"create_uid",
"create_date",
"write_uid",
"write_date",
]);
const paramsRead = [inParamsRead];
odooClient.execute_kw(
"pivi_assets.bounds",
"read",
paramsRead,
async function (err2, bound) {
if (err2) {
console.log(err2);
return res.status(500).json({
error: "Read Error: " + err2.message,
});
} else {
bounds = bound;
odooClient.execute_kw(
"ir.attachment",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res.status(500).json({
error:
"Search Error: " + err.message,
});
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
inParamsRead.push([
"id",
"name",
"local_url",
"res_id",
]);
const paramsRead = [inParamsRead];
odooClient.execute_kw(
"ir.attachment",
"read",
paramsRead,
async function (err2, image) {
if (err2) {
console.log(err2);
return res.status(500).json({
error:
"Read Error: " + err2.message,
});
} else {
images = image;
const asset = recordsArray.map(
(item) => {
// Find matching attributes based on the numeric part of attr.assets
const matchedAttr =
attributes.filter(
(attribute) =>
item.attributes.some(
(attrId) =>
attrId ===
attribute.id
) // Compare to the first element of attr.assets
);
// Find matching bounds based on the numeric part of bounds.assets
const matchedBounds =
bounds.filter(
(bound) =>
item.bounds.some(
(boundId) =>
boundId === bound.id
) // Compare to the first element of bounds.assets
);
// Find matching images based on data.id == images.res_id
const matchedImages =
images.filter(
(image) =>
image.res_id === item.id
);
// Construct the asset object for this item
return {
attr: matchedAttr,
bounds: matchedBounds,
data: item,
images: matchedImages,
};
}
);
// res.json({
// data: recordsArray,
// attr: attributes,
// bounds: bounds,
// images: images,
// });
res.json(asset);
}
let pendingRequests =
records.length;
}
);
}
);
}
}
);
}
);
}
}
);
}
);
}
let pendingRequests = records.length;
}
);
}
);
});
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "Data Fetch Error: " + error.message });
}
});
app.get("/get-orders", async (req, res) => {
try {
odooClient2.connect(async function (err) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Connection Error: " + err.message });
}
console.log("Connected to Odoo server.");
// Fetch asset IDs
const inParams = [];
inParams.push([["name", "!=", false]]);
inParams.push(parseInt(req.query.offset) || 0); //offset
inParams.push(parseInt(req.query.limit) || 0); //Limit
const params = [inParams];
const assets = [];
let recordsArray = [];
let attributes = [];
let bounds = [];
let images = [];
odooClient2.execute_kw(
"pos.order",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Search Error: " + err.message });
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
const paramsRead = [inParamsRead];
odooClient2.execute_kw(
"pos.order",
"read",
paramsRead,
async function (err2, records) {
if (err2) {
console.log(err2);
return res
.status(500)
.json({ error: "Read Error: " + err2.message });
} else {
recordsArray = records;
res.json(recordsArray);
}
let pendingRequests = records.length;
}
);
}
);
});
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "Data Fetch Error: " + error.message });
}
});
app.get("/get-products", async (req, res) => {
try {
odooClient2.connect(async function (err) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Connection Error: " + err.message });
}
console.log("Connected to Odoo server.");
// Fetch asset IDs
const inParams = [];
inParams.push([["name", "!=", false]]);
inParams.push(parseInt(req.query.offset) || 0); //offset
inParams.push(parseInt(req.query.limit) || 0); //Limit
const params = [inParams];
const assets = [];
let recordsArray = [];
let attributes = [];
let bounds = [];
let images = [];
odooClient2.execute_kw(
"product.template",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Search Error: " + err.message });
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
inParamsRead.push(["id", "name"]);
const paramsRead = [inParamsRead];
odooClient2.execute_kw(
"product.template",
"read",
paramsRead,
async function (err2, records) {
if (err2) {
console.log(err2);
return res
.status(500)
.json({ error: "Read Error: " + err2.message });
} else {
recordsArray = records;
res.json(recordsArray);
}
let pendingRequests = records.length;
}
);
}
);
});
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "Data Fetch Error: " + error.message });
}
});
app.get("/get-product_ordered", async (req, res) => {
try {
odooClient2.connect(async function (err) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Connection Error: " + err.message });
}
console.log("Connected to Odoo server.");
// Fetch asset IDs
const inParams = [];
inParams.push([["name", "!=", false]]);
inParams.push(parseInt(req.query.offset) || 0); //offset
inParams.push(parseInt(req.query.limit) || 0); //Limit
const params = [inParams];
const assets = [];
let recordsArray = [];
let attributes = [];
let bounds = [];
let images = [];
odooClient2.execute_kw(
"pos.order.line",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Search Error: " + err.message });
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
// inParamsRead.push([
// "id",
// "name",
// ]);
const paramsRead = [inParamsRead];
odooClient2.execute_kw(
"pos.order.line",
"read",
paramsRead,
async function (err2, records) {
if (err2) {
console.log(err2);
return res
.status(500)
.json({ error: "Read Error: " + err2.message });
} else {
recordsArray = records;
res.json(recordsArray);
}
let pendingRequests = records.length;
}
);
}
);
});
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "Data Fetch Error: " + error.message });
}
});
app.get("/get-stages", async (req, res) => {
try {
odooClient2.connect(async function (err) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Connection Error: " + err.message });
}
console.log("Connected to Odoo server.");
// Fetch asset IDs
const inParams = [];
inParams.push([["name", "!=", false]]);
inParams.push(parseInt(req.query.offset) || 0);
inParams.push(parseInt(req.query.limit) || 0);
const params = [inParams];
const assets = [];
let recordsArray = [];
let attributes = [];
let bounds = [];
let images = [];
odooClient2.execute_kw(
"kds.stages",
"search",
params,
async function (err, ids) {
if (err) {
console.log(err);
return res
.status(500)
.json({ error: "Search Error: " + err.message });
}
if (ids.length === 0) {
return res.json([]); // No assets found
}
// Fetch asset records
const inParamsRead = [];
inParamsRead.push(ids); // IDs
// inParamsRead.push([
// "id",
// "name",
// ]);
const paramsRead = [inParamsRead];
odooClient2.execute_kw(
"kds.stages",
"read",
paramsRead,
async function (err2, records) {
if (err2) {
console.log(err2);
return res
.status(500)
.json({ error: "Read Error: " + err2.message });
} else {
recordsArray = records;
res.json(recordsArray);
}
let pendingRequests = records.length;
}
);
}
);
});
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "Data Fetch Error: " + error.message });
}
});
app.post('/update-order-state', async (req, res) => {
const { id, state } = req.body; // Order ID and new state passed in the request body
if (!id || !state) {
return res.status(400).json({ error: 'Order ID and state are required.' });
}
try {
odooClient2.connect(function (err) {
if (err) {
console.log(err);
return res.status(500).json({ error: 'Connection Error: ' + err.message });
}
console.log('Connected to Odoo server.');
// Search for the order by ID
const inParams = [];
inParams.push([['id', '=', id]]); // Find the order by its ID
const params = [inParams];
odooClient2.execute_kw('pos.order', 'search', params, function (err, orderIds) {
if (err) {
console.log(err);
return res.status(500).json({ error: 'Search Error: ' + err.message });
}
if (orderIds.length === 0) {
return res.status(404).json({ error: 'Order not found.' });
}
// Update the state of the order
const inParamsUpdate = [];
inParamsUpdate.push(orderIds); // Order IDs to update
inParamsUpdate.push({ state: state }); // Fields to update
const paramsUpdate = [inParamsUpdate];
odooClient2.execute_kw('pos.order', 'write', paramsUpdate, function (err2, result) {
if (err2) {
console.log(err2);
return res.status(500).json({ error: 'Update Error: ' + err2.message });
}
if (result) {
return res.json({ success: true, message: `Order ID ${id} updated to state: ${state}` });
} else {
return res.status(500).json({ error: 'Failed to update order state.' });
}
});
});
});
} catch (error) {
console.error('Error:', error);
return res.status(500).json({ error: 'Update Error: ' + error.message });
}
});
function fetchOdooData(model, method, params) {
return new Promise((resolve, reject) => {
odooClient.execute_kw(model, method, params, (err, data) => {
if (err) return reject(err);
resolve(data);
});
});
}
/* MONGOOSE SETUP */ /* MONGOOSE SETUP */
const PORT = process.env.PORT || 3000; const PORT = process.env.PORT || 3002;
// mongoose // mongoose
// .connect(process.env.MONGO_URL, { // .connect(process.env.MONGO_URL, {
// useNewUrlParser: true, // useNewUrlParser: true,

View File

@ -1,36 +0,0 @@
import mongoose from "mongoose";
const CollectionSchema = mongoose.Schema(
{
name: {
type: String,
// required: true,
},
created_by: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
header: [
{
key: {
type: String,
},
value: {
type: String,
},
//required: true,
},
],
endpoints: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Endpoint",
},
],
},
{ timestamps: true }
);
const Collection = mongoose.model("Collection", CollectionSchema);
export default Collection;

View File

@ -1,67 +0,0 @@
import mongoose from "mongoose";
const EndpointSchema = mongoose.Schema(
{
endpoint: {
type: String,
// required: true,
},
name: {
type: String,
// required: true,
},
method: {
type: String,
// required: true,
},
collection_id: {
type: mongoose.Schema.Types.ObjectId,
ref: "Collection",
},
// created_by: {
// type: mongoose.Schema.Types.ObjectId,
// ref: "User",
// },
body_json: {
type: Array,
},
form_data: [
{
key: {
type: String,
},
value: {
type: String,
},
//required: true,
},
],
header: [
{
key: {
type: String,
},
value: {
type: String,
},
//required: true,
},
],
params: [
{
key: {
type: String,
},
value: {
type: String,
},
//required: true,
},
],
},
{ timestamps: true }
);
const Endpoint = mongoose.model("Endpoint", EndpointSchema);
export default Endpoint;

38
models/KDS.js Normal file
View File

@ -0,0 +1,38 @@
import mongoose, { Schema } from "mongoose";
// Define the KDSItem schema
const KDSItemSchema = new Schema(
{
ordered_prod_id: { type: Number },
product_id: { type: Number },
quantity: { type: Number },
order_id: { type: Number },
product_name: { type: String },
note: { type: String },
},
{ _id: false }
);
// Define the KDS schema
const KDSSchema = new Schema(
{
order_id: { type: Number, required: true, unique: true },
order_name: { type: String },
order_date: { type: String },
cancelled: { type: Boolean },
ref_ticket: { type: String },
take_away: { type: Boolean },
seat_id: { type: String },
customer_count: { type: Number },
row_pos: { type: Number },
ref_id: { type: String, required: true, unique: true },
items: { type: [KDSItemSchema] },
stage: { type: String },
state: { type: String },
duration: { type: Number },
},
{ timestamps: true }
);
const KDSModel = mongoose.model("KDS", KDSSchema);
export default KDSModel;

33
models/KDSGrouped.js Normal file
View File

@ -0,0 +1,33 @@
import mongoose, { Schema } from "mongoose";
// Define the KDSItem schema
const KDSItemSchema = new Schema(
{
ordered_prod_id: { type: Number },
product_id: { type: Number },
quantity: { type: Number },
order_id: { type: Number },
product_name: { type: String },
note: { type: String },
},
{ _id: false }
);
// Define the KDS schema
const KDSSchema = new Schema({
order_id: { type: Number, required: true, unique: true },
order_name: { type: String },
order_date: { type: String },
cancelled: { type: Boolean },
ref_ticket: { type: String },
take_away: { type: Boolean },
seat_id: { type: String },
customer_count: { type: Number },
row_pos: { type: Number },
ref_id: { type: String, required: true, unique: true },
items: { type: [KDSItemSchema] },
stage: { type: String },
duration: { type: Number },
});
const KDSGrouped = mongoose.model("KDS", KDSSchema);
export default KDSGrouped;

126
package-lock.json generated
View File

@ -23,8 +23,10 @@
"morgan": "^1.10.0", "morgan": "^1.10.0",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"nodemon": "^3.1.4", "nodemon": "^3.1.4",
"odoo-xmlrpc": "^1.0.8",
"streamifier": "^0.1.1", "streamifier": "^0.1.1",
"ws": "^8.18.0" "ws": "^8.18.0",
"xmlrpc": "^1.3.2"
} }
}, },
"node_modules/@mapbox/node-pre-gyp": { "node_modules/@mapbox/node-pre-gyp": {
@ -1638,6 +1640,19 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/odoo-xmlrpc": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/odoo-xmlrpc/-/odoo-xmlrpc-1.0.8.tgz",
"integrity": "sha512-tkUwrlyARnkSsbwcQqpLDgyMXNC29cMTU4EZd1JmWK9+Q+gX19EVoqsYfrUDrVAu3gXQKDW/+UvAXibbP/ZDwQ==",
"dependencies": {
"url": "*",
"xmlrpc": "^1.3.1"
},
"engines": {
"node": ">=0.8",
"npm": ">=1.0.0"
}
},
"node_modules/on-finished": { "node_modules/on-finished": {
"version": "2.4.1", "version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
@ -1855,6 +1870,11 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
}, },
"node_modules/sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"node_modules/semver": { "node_modules/semver": {
"version": "7.6.3", "version": "7.6.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
@ -2147,6 +2167,37 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/url": {
"version": "0.11.4",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.4.tgz",
"integrity": "sha512-oCwdVC7mTuWiPyjLUz/COz5TLk6wgp0RCsN+wHZ2Ekneac9w8uuV0njcbbie2ME+Vs+d6duwmYuR3HgQXs1fOg==",
"dependencies": {
"punycode": "^1.4.1",
"qs": "^6.12.3"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/url/node_modules/punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ=="
},
"node_modules/url/node_modules/qs": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
"dependencies": {
"side-channel": "^1.0.6"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/util-deprecate": { "node_modules/util-deprecate": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@ -2221,6 +2272,27 @@
} }
} }
}, },
"node_modules/xmlbuilder": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
"integrity": "sha512-eKRAFz04jghooy8muekqzo8uCSVNeyRedbuJrp0fovbLIi7wlsYtdUn3vBAAPq2Y3/0xMz2WMEUQ8yhVVO9Stw==",
"engines": {
"node": ">=4.0"
}
},
"node_modules/xmlrpc": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/xmlrpc/-/xmlrpc-1.3.2.tgz",
"integrity": "sha512-jQf5gbrP6wvzN71fgkcPPkF4bF/Wyovd7Xdff8d6/ihxYmgETQYSuTc+Hl+tsh/jmgPLro/Aro48LMFlIyEKKQ==",
"dependencies": {
"sax": "1.2.x",
"xmlbuilder": "8.2.x"
},
"engines": {
"node": ">=0.8",
"npm": ">=1.0.0"
}
},
"node_modules/xtend": { "node_modules/xtend": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
@ -3422,6 +3494,15 @@
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz",
"integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==" "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g=="
}, },
"odoo-xmlrpc": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/odoo-xmlrpc/-/odoo-xmlrpc-1.0.8.tgz",
"integrity": "sha512-tkUwrlyARnkSsbwcQqpLDgyMXNC29cMTU4EZd1JmWK9+Q+gX19EVoqsYfrUDrVAu3gXQKDW/+UvAXibbP/ZDwQ==",
"requires": {
"url": "*",
"xmlrpc": "^1.3.1"
}
},
"on-finished": { "on-finished": {
"version": "2.4.1", "version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
@ -3576,6 +3657,11 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
}, },
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"semver": { "semver": {
"version": "7.6.3", "version": "7.6.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
@ -3805,6 +3891,30 @@
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="
}, },
"url": {
"version": "0.11.4",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.4.tgz",
"integrity": "sha512-oCwdVC7mTuWiPyjLUz/COz5TLk6wgp0RCsN+wHZ2Ekneac9w8uuV0njcbbie2ME+Vs+d6duwmYuR3HgQXs1fOg==",
"requires": {
"punycode": "^1.4.1",
"qs": "^6.12.3"
},
"dependencies": {
"punycode": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
"integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ=="
},
"qs": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
"requires": {
"side-channel": "^1.0.6"
}
}
}
},
"util-deprecate": { "util-deprecate": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@ -3853,6 +3963,20 @@
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
"requires": {} "requires": {}
}, },
"xmlbuilder": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
"integrity": "sha512-eKRAFz04jghooy8muekqzo8uCSVNeyRedbuJrp0fovbLIi7wlsYtdUn3vBAAPq2Y3/0xMz2WMEUQ8yhVVO9Stw=="
},
"xmlrpc": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/xmlrpc/-/xmlrpc-1.3.2.tgz",
"integrity": "sha512-jQf5gbrP6wvzN71fgkcPPkF4bF/Wyovd7Xdff8d6/ihxYmgETQYSuTc+Hl+tsh/jmgPLro/Aro48LMFlIyEKKQ==",
"requires": {
"sax": "1.2.x",
"xmlbuilder": "8.2.x"
}
},
"xtend": { "xtend": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",

View File

@ -25,7 +25,9 @@
"morgan": "^1.10.0", "morgan": "^1.10.0",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"nodemon": "^3.1.4", "nodemon": "^3.1.4",
"odoo-xmlrpc": "^1.0.8",
"streamifier": "^0.1.1", "streamifier": "^0.1.1",
"ws": "^8.18.0" "ws": "^8.18.0",
"xmlrpc": "^1.3.2"
} }
} }

View File

@ -1,52 +0,0 @@
import express from "express";
import {
getCollection,
getCollections,
deleteCollection,
createCollection,
updateCollection,
updateCollectionByEndpoint,
} from "../controllers/collection.js";
import { verifyToken } from "../middleware/auth.js";
import logApiCall from "../middleware/log.js";
const router = express.Router();
/* READ */
router.get(
"/",
// verifyToken,
getCollections
);
router.get(
"/:id",
// verifyToken,
getCollection
);
router.post(
"/create",
// verifyToken,
// logApiCall,
createCollection
);
router.patch(
"/update/:id",
// verifyToken,
// logApiCall,
updateCollection
);
router.patch(
"/update/:id/endpoint",
// verifyToken,
// logApiCall,
updateCollectionByEndpoint
);
router.delete(
"/:id/delete",
// verifyToken,
// logApiCall,
deleteCollection
);
export default router;

View File

@ -1,48 +0,0 @@
import express from "express";
import {
getEndpoint,
getEndpoints,
deleteEndpoint,
createEndpoint,
updateEndpoint,
} from "../controllers/endpoint.js";
import { verifyToken } from "../middleware/auth.js";
import logApiCall from "../middleware/log.js";
const router = express.Router();
/* READ */
router.get(
"/",
// verifyToken,
getEndpoints
);
router.get(
"/:id",
// verifyToken,
getEndpoint
);
router.post(
"/create",
// verifyToken,
// logApiCall,
createEndpoint
);
router.patch(
"/update/:id",
// verifyToken,
// logApiCall,
updateEndpoint
);
router.delete(
"/:id/delete",
// verifyToken,
// logApiCall,
deleteEndpoint
);
export default router;

19
routes/kds.js Normal file
View File

@ -0,0 +1,19 @@
import express from "express";
import {
deleteKDS,
updateKDS,
getAllKDS,
createKDS,
getKDS,
} from "../controllers/kds.js";
const router = express.Router();
router.post("/", createKDS);
router.get("/", getAllKDS);
router.get("/:id", getKDS);
router.patch("/:id", updateKDS);
router.delete("/:id", deleteKDS);
export default router;