Refactor routes and schemas: reorganized service imports, updated user and auth routes, and modified schema paths for better structure. Removed unused routes and services to streamline the codebase.
This commit is contained in:
parent
11d80fb76e
commit
dd858c8451
@ -29,7 +29,7 @@ import * as fs from "fs";
|
|||||||
import cron from "node-cron";
|
import cron from "node-cron";
|
||||||
import ReseedAction from "./mongo/ReseedAction.js";
|
import ReseedAction from "./mongo/ReseedAction.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { populateUserMiddleware } from "./services/auth/index.js";
|
import { populateUserMiddleware } from "./services/misc/auth.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
import { userModel } from "../schemas/user.schema.js";
|
import { userModel } from "../schemas/management/user.schema.js";
|
||||||
import { dbConnect } from "./index.js";
|
import { dbConnect } from "./index.js";
|
||||||
|
|
||||||
const ReseedAction = () => {
|
const ReseedAction = () => {
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
import userRoutes from "./users/index.js";
|
import userRoutes from "./management/users.js";
|
||||||
import authRoutes from "./auth/index.js";
|
import authRoutes from "./misc/auth.js";
|
||||||
import printerRoutes from "./printers/index.js";
|
import printerRoutes from "./production/printers.js";
|
||||||
import jobRoutes from "./jobs/index.js";
|
import jobRoutes from "./production/jobs.js";
|
||||||
import gcodeFileRoutes from "./gcodefiles/index.js";
|
import gcodeFileRoutes from "./production/gcodefiles.js";
|
||||||
import filamentRoutes from "./filaments/index.js";
|
import filamentRoutes from "./production/filaments.js";
|
||||||
import spotlightRoutes from "./spotlight/index.js";
|
import spotlightRoutes from "./misc/spotlight.js";
|
||||||
import partRoutes from "./parts/index.js";
|
import partRoutes from "./management/parts.js";
|
||||||
import productRoutes from "./products/index.js";
|
import productRoutes from "./management/products.js";
|
||||||
import vendorRoutes from "./vendors/index.js";
|
import vendorRoutes from "./management/vendors.js";
|
||||||
import materialRoutes from "./materials/index.js";
|
import materialRoutes from "./management/materials.js";
|
||||||
import partStockRoutes from "./partstocks/index.js";
|
import partStockRoutes from "./inventory/partstocks.js";
|
||||||
import filamentStockRoutes from "./filamentstocks/index.js";
|
import filamentStockRoutes from "./inventory/filamentstocks.js";
|
||||||
import stockEventRoutes from "./stockevents/index.js";
|
import stockEventRoutes from "./inventory/stockevents.js";
|
||||||
import stockAuditRoutes from "./stockaudits/index.js";
|
import stockAuditRoutes from "./inventory/stockaudits.js";
|
||||||
import auditLogRoutes from "./auditlogs/index.js";
|
import auditLogRoutes from "./management/auditlogs.js";
|
||||||
import noteTypeRoutes from "./notetypes/index.js";
|
import noteTypeRoutes from "./management/notetypes.js";
|
||||||
import noteRoutes from "./notes/index.js"
|
import noteRoutes from "./misc/notes.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
userRoutes,
|
userRoutes,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
getFilamentStockRouteHandler,
|
getFilamentStockRouteHandler,
|
||||||
editFilamentStockRouteHandler,
|
editFilamentStockRouteHandler,
|
||||||
newFilamentStockRouteHandler,
|
newFilamentStockRouteHandler,
|
||||||
} from "../../services/filamentstocks/index.js";
|
} from "../../services/inventory/filamentstocks.js";
|
||||||
|
|
||||||
// list of filamentStocks
|
// list of filamentStocks
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
getPartStockRouteHandler,
|
getPartStockRouteHandler,
|
||||||
editPartStockRouteHandler,
|
editPartStockRouteHandler,
|
||||||
newPartStockRouteHandler,
|
newPartStockRouteHandler,
|
||||||
} from "../../services/partstocks/index.js";
|
} from "../../services/inventory/partstocks.js";
|
||||||
|
|
||||||
// list of partStocks
|
// list of partStocks
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -9,7 +9,7 @@ import {
|
|||||||
newStockAuditRouteHandler,
|
newStockAuditRouteHandler,
|
||||||
updateStockAuditRouteHandler,
|
updateStockAuditRouteHandler,
|
||||||
deleteStockAuditRouteHandler,
|
deleteStockAuditRouteHandler,
|
||||||
} from "../../services/stockaudits/index.js";
|
} from "../../services/inventory/stockaudits.js";
|
||||||
|
|
||||||
// List stock audits
|
// List stock audits
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -7,7 +7,7 @@ import {
|
|||||||
listStockEventsRouteHandler,
|
listStockEventsRouteHandler,
|
||||||
getStockEventRouteHandler,
|
getStockEventRouteHandler,
|
||||||
newStockEventRouteHandler,
|
newStockEventRouteHandler,
|
||||||
} from "../../services/stockevents/index.js";
|
} from "../../services/inventory/stockevents.js";
|
||||||
|
|
||||||
// List stock events
|
// List stock events
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { listAuditLogsRouteHandler, getAuditLogRouteHandler } from '../../services/auditlogs/index.js';
|
import { listAuditLogsRouteHandler, getAuditLogRouteHandler } from '../../services/management/auditlogs.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
getMaterialRouteHandler,
|
getMaterialRouteHandler,
|
||||||
editMaterialRouteHandler,
|
editMaterialRouteHandler,
|
||||||
newMaterialRouteHandler,
|
newMaterialRouteHandler,
|
||||||
} from "../../services/materials/index.js";
|
} from "../../services/management/materials.js";
|
||||||
|
|
||||||
// list of materials
|
// list of materials
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -5,7 +5,7 @@ import {
|
|||||||
getNoteTypeRouteHandler,
|
getNoteTypeRouteHandler,
|
||||||
editNoteTypeRouteHandler,
|
editNoteTypeRouteHandler,
|
||||||
newNoteTypeRouteHandler,
|
newNoteTypeRouteHandler,
|
||||||
} from "../../services/notetypes/index.js";
|
} from "../../services/management/notetypes.js";
|
||||||
import { parseFilter } from "../../util/index.js";
|
import { parseFilter } from "../../util/index.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -10,7 +10,7 @@ import {
|
|||||||
newPartRouteHandler,
|
newPartRouteHandler,
|
||||||
uploadPartFileContentRouteHandler,
|
uploadPartFileContentRouteHandler,
|
||||||
getPartFileContentRouteHandler,
|
getPartFileContentRouteHandler,
|
||||||
} from "../../services/parts/index.js";
|
} from "../../services/management/parts.js";
|
||||||
|
|
||||||
// list of parts
|
// list of parts
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
getProductRouteHandler,
|
getProductRouteHandler,
|
||||||
editProductRouteHandler,
|
editProductRouteHandler,
|
||||||
newProductRouteHandler,
|
newProductRouteHandler,
|
||||||
} from "../../services/products/index.js";
|
} from "../../services/management/products.js";
|
||||||
|
|
||||||
// list of products
|
// list of products
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -7,7 +7,7 @@ import {
|
|||||||
listUsersRouteHandler,
|
listUsersRouteHandler,
|
||||||
getUserRouteHandler,
|
getUserRouteHandler,
|
||||||
editUserRouteHandler,
|
editUserRouteHandler,
|
||||||
} from "../../services/users/index.js";
|
} from "../../services/management/users.js";
|
||||||
|
|
||||||
// list of users
|
// list of users
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
getVendorRouteHandler,
|
getVendorRouteHandler,
|
||||||
editVendorRouteHandler,
|
editVendorRouteHandler,
|
||||||
newVendorRouteHandler,
|
newVendorRouteHandler,
|
||||||
} from "../../services/vendors/index.js";
|
} from "../../services/management/vendors.js";
|
||||||
|
|
||||||
// list of vendors
|
// list of vendors
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -7,7 +7,7 @@ import {
|
|||||||
userRouteHandler,
|
userRouteHandler,
|
||||||
logoutRouteHandler,
|
logoutRouteHandler,
|
||||||
refreshTokenRouteHandler,
|
refreshTokenRouteHandler,
|
||||||
} from "../../services/auth/index.js";
|
} from "../../services/misc/auth.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ import {
|
|||||||
editNoteRouteHandler,
|
editNoteRouteHandler,
|
||||||
newNoteRouteHandler,
|
newNoteRouteHandler,
|
||||||
deleteNoteRouteHandler
|
deleteNoteRouteHandler
|
||||||
} from "../../services/notes/index.js";
|
} from "../../services/misc/notes.js";
|
||||||
import { parseFilter } from "../../util/index.js";
|
import { parseFilter } from "../../util/index.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -2,7 +2,7 @@ import express from "express";
|
|||||||
import { isAuthenticated } from "../../keycloak.js";
|
import { isAuthenticated } from "../../keycloak.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
import { getSpotlightRouteHandler } from "../../services/spotlight/index.js";
|
import { getSpotlightRouteHandler } from "../../services/misc/spotlight.js";
|
||||||
|
|
||||||
router.get("/:query", isAuthenticated, (req, res) => {
|
router.get("/:query", isAuthenticated, (req, res) => {
|
||||||
getSpotlightRouteHandler(req, res);
|
getSpotlightRouteHandler(req, res);
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
getFilamentRouteHandler,
|
getFilamentRouteHandler,
|
||||||
editFilamentRouteHandler,
|
editFilamentRouteHandler,
|
||||||
newFilamentRouteHandler,
|
newFilamentRouteHandler,
|
||||||
} from "../../services/filaments/index.js";
|
} from "../../services/management/filaments.js";
|
||||||
|
|
||||||
// list of filaments
|
// list of filaments
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -11,7 +11,7 @@ import {
|
|||||||
parseGCodeFileHandler,
|
parseGCodeFileHandler,
|
||||||
uploadGCodeFileContentRouteHandler,
|
uploadGCodeFileContentRouteHandler,
|
||||||
getGCodeFileContentRouteHandler,
|
getGCodeFileContentRouteHandler,
|
||||||
} from "../../services/gcodefiles/index.js";
|
} from "../../services/production/gcodefiles.js";
|
||||||
|
|
||||||
// list of printers
|
// list of printers
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -8,7 +8,7 @@ import {
|
|||||||
editJobRouteHandler,
|
editJobRouteHandler,
|
||||||
createJobRouteHandler,
|
createJobRouteHandler,
|
||||||
getJobStatsRouteHandler
|
getJobStatsRouteHandler
|
||||||
} from "../../services/jobs/index.js";
|
} from "../../services/production/jobs.js";
|
||||||
|
|
||||||
// list of print jobs
|
// list of print jobs
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -9,7 +9,7 @@ import {
|
|||||||
getPrinterRouteHandler,
|
getPrinterRouteHandler,
|
||||||
createPrinterRouteHandler,
|
createPrinterRouteHandler,
|
||||||
getPrinterStatsRouteHandler,
|
getPrinterStatsRouteHandler,
|
||||||
} from "../../services/printers/index.js";
|
} from "../../services/production/printers.js";
|
||||||
|
|
||||||
// list of printers
|
// list of printers
|
||||||
router.get("/", isAuthenticated, (req, res) => {
|
router.get("/", isAuthenticated, (req, res) => {
|
||||||
@ -7,9 +7,8 @@ const partSchema = new Schema(
|
|||||||
name: { type: String, required: true },
|
name: { type: String, required: true },
|
||||||
fileName: { type: String, required: false },
|
fileName: { type: String, required: false },
|
||||||
product: { type: mongoose.Schema.Types.ObjectId, ref: "Product" },
|
product: { type: mongoose.Schema.Types.ObjectId, ref: "Product" },
|
||||||
useGlobalPricing: { type: Boolean, default: true },
|
globalPricing: { type: Boolean, default: true },
|
||||||
marginOrPrice: { type: Boolean, default: false },
|
priceMode: { type: String, default: 'margin' },
|
||||||
margin: { type: Number, required: false },
|
|
||||||
price: { type: Number, required: false },
|
price: { type: Number, required: false },
|
||||||
},
|
},
|
||||||
{ timestamps: true },
|
{ timestamps: true },
|
||||||
@ -7,8 +7,7 @@ const productSchema = new Schema(
|
|||||||
name: { type: String, required: true },
|
name: { type: String, required: true },
|
||||||
tags: [{ type: String }],
|
tags: [{ type: String }],
|
||||||
version: { type: String },
|
version: { type: String },
|
||||||
marginOrPrice: { type: Boolean, default: false },
|
priceMode: { type: String, default: 'margin' },
|
||||||
margin: { type: Number, required: false },
|
|
||||||
price: { type: Number, required: false },
|
price: { type: Number, required: false },
|
||||||
vendor: { type: Schema.Types.ObjectId, ref: "Vendor", required: true },
|
vendor: { type: Schema.Types.ObjectId, ref: "Vendor", required: true },
|
||||||
parts: [{ type: mongoose.Schema.Types.ObjectId, ref: "Part" }],
|
parts: [{ type: mongoose.Schema.Types.ObjectId, ref: "Part" }],
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import mongoose from "mongoose";
|
|
||||||
|
|
||||||
const passwordResetSchema = new mongoose.Schema({
|
|
||||||
email: { required: true, type: String },
|
|
||||||
token: { required: true, type: String },
|
|
||||||
createdAt: { type: Date },
|
|
||||||
});
|
|
||||||
|
|
||||||
passwordResetSchema.virtual("id").get(function () {
|
|
||||||
return this._id.toHexString();
|
|
||||||
});
|
|
||||||
|
|
||||||
passwordResetSchema.set("toJSON", { virtuals: true });
|
|
||||||
|
|
||||||
export const passwordResetModel = mongoose.model("PasswordReset", passwordResetSchema);
|
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { filamentStockModel } from "../../schemas/filamentstock.schema.js";
|
import { filamentStockModel } from "../../schemas/inventory/filamentstock.schema.js";
|
||||||
import { filamentModel } from "../../schemas/filament.schema.js";
|
import { filamentModel } from "../../schemas/management/filament.schema.js";
|
||||||
import { stockEventModel } from "../../schemas/stockevent.schema.js";
|
import { stockEventModel } from "../../schemas/inventory/stockevent.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { partStockModel } from "../../schemas/partstock.schema.js";
|
import { partStockModel } from "../../schemas/inventory/partstock.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { stockAuditModel } from "../../schemas/stockaudit.schema.js";
|
import { stockAuditModel } from "../../schemas/inventory/stockaudit.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { stockEventModel } from "../../schemas/stockevent.schema.js";
|
import { stockEventModel } from "../../schemas/inventory/stockevent.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { auditLogModel } from '../../schemas/auditlog.schema.js';
|
import { auditLogModel } from '../../schemas/management/auditlog.schema.js';
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
@ -1,10 +1,10 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { filamentModel } from "../../schemas/filament.schema.js";
|
import { filamentModel } from "../../schemas/management/filament.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { materialModel } from "../../schemas/material.schema.js";
|
import { materialModel } from "../../schemas/management/material.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { noteTypeModel } from "../../schemas/notetype.schema.js";
|
import { noteTypeModel } from "../../schemas/management/notetype.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,12 +1,12 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { partModel } from "../../schemas/part.schema.js";
|
import { partModel } from "../../schemas/management/part.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,10 +1,10 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { productModel } from "../../schemas/product.schema.js";
|
import { productModel } from "../../schemas/management/product.schema.js";
|
||||||
import { partModel } from "../../schemas/part.schema.js";
|
import { partModel } from "../../schemas/management/part.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,21 +1,21 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { jobModel } from "../../schemas/job.schema.js";
|
import { jobModel } from "../../schemas/production/job.schema.js";
|
||||||
import { subJobModel } from "../../schemas/subjob.schema.js";
|
import { subJobModel } from "../../schemas/production/subjob.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { printerModel } from "../../schemas/printer.schema.js";
|
import { printerModel } from "../../schemas/production/printer.schema.js";
|
||||||
import { filamentModel } from "../../schemas/filament.schema.js";
|
import { filamentModel } from "../../schemas/management/filament.schema.js";
|
||||||
import { gcodeFileModel } from "../../schemas/gcodefile.schema.js";
|
import { gcodeFileModel } from "../../schemas/production/gcodefile.schema.js";
|
||||||
import { partModel } from "../../schemas/part.schema.js";
|
import { partModel } from "../../schemas/management/part.schema.js";
|
||||||
import { productModel } from "../../schemas/product.schema.js";
|
import { productModel } from "../../schemas/management/product.schema.js";
|
||||||
import { vendorModel } from "../../schemas/vendor.schema.js";
|
import { vendorModel } from "../../schemas/management/vendor.schema.js";
|
||||||
import { filamentStockModel } from "../../schemas/filamentstock.schema.js";
|
import { filamentStockModel } from "../../schemas/inventory/filamentstock.schema.js";
|
||||||
import { stockEventModel } from "../../schemas/stockevent.schema.js";
|
import { stockEventModel } from "../../schemas/inventory/stockevent.schema.js";
|
||||||
import { stockAuditModel } from "../../schemas/stockaudit.schema.js";
|
import { stockAuditModel } from "../../schemas/inventory/stockaudit.schema.js";
|
||||||
import { partStockModel } from "../../schemas/partstock.schema.js";
|
import { partStockModel } from "../../schemas/inventory/partstock.schema.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
import { userModel } from "../../schemas/user.schema.js";
|
import { userModel } from "../../schemas/management/user.schema.js";
|
||||||
import { noteTypeModel } from "../../schemas/notetype.schema.js";
|
import { noteTypeModel } from "../../schemas/management/notetype.schema.js";
|
||||||
import { noteModel } from "../../schemas/note.schema.js";
|
import { noteModel } from "../../schemas/misc/note.schema.js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
@ -1,10 +1,10 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { userModel } from "../../schemas/user.schema.js";
|
import { userModel } from "../../schemas/management/user.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,10 +1,10 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { vendorModel } from "../../schemas/vendor.schema.js";
|
import { vendorModel } from "../../schemas/management/vendor.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -2,7 +2,7 @@ import dotenv from "dotenv";
|
|||||||
import { keycloak } from "../../keycloak.js";
|
import { keycloak } from "../../keycloak.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { userModel } from "../../schemas/user.schema.js";
|
import { userModel } from "../../schemas/management/user.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { noteModel } from "../../schemas/note.schema.js";
|
import { noteModel } from "../../schemas/misc/note.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
169
src/services/misc/spotlight.js
Normal file
169
src/services/misc/spotlight.js
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
import dotenv from "dotenv";
|
||||||
|
import log4js from "log4js";
|
||||||
|
import mongoose from "mongoose";
|
||||||
|
import { jobModel } from "../../schemas/production/job.schema.js";
|
||||||
|
import { subJobModel } from "../../schemas/production/subjob.schema.js";
|
||||||
|
import { printerModel } from "../../schemas/production/printer.schema.js";
|
||||||
|
import { filamentModel } from "../../schemas/management/filament.schema.js";
|
||||||
|
import { gcodeFileModel } from "../../schemas/production/gcodefile.schema.js";
|
||||||
|
import { partModel } from "../../schemas/management/part.schema.js";
|
||||||
|
import { productModel } from "../../schemas/management/product.schema.js";
|
||||||
|
import { vendorModel } from "../../schemas/management/vendor.schema.js";
|
||||||
|
import { filamentStockModel } from "../../schemas/inventory/filamentstock.schema.js";
|
||||||
|
import { stockEventModel } from "../../schemas/inventory/stockevent.schema.js";
|
||||||
|
import { stockAuditModel } from "../../schemas/inventory/stockaudit.schema.js";
|
||||||
|
import { partStockModel } from "../../schemas/inventory/partstock.schema.js";
|
||||||
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
import { userModel } from "../../schemas/management/user.schema.js";
|
||||||
|
import { noteTypeModel } from "../../schemas/management/notetype.schema.js";
|
||||||
|
import { noteModel } from "../../schemas/misc/note.schema.js";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const logger = log4js.getLogger("Jobs");
|
||||||
|
logger.level = process.env.LOG_LEVEL;
|
||||||
|
|
||||||
|
// Map prefixes to models and id fields
|
||||||
|
const PREFIX_MODEL_MAP = {
|
||||||
|
PRN: { model: printerModel, idField: '_id', type: 'printer' },
|
||||||
|
FIL: { model: filamentModel, idField: '_id', type: 'filament' },
|
||||||
|
SPL: { model: null, idField: '_id', type: 'spool' }, // No spool model found
|
||||||
|
GCF: { model: gcodeFileModel, idField: '_id', type: 'gcodefile' },
|
||||||
|
JOB: { model: jobModel, idField: '_id', type: 'job' },
|
||||||
|
PRT: { model: partModel, idField: '_id', type: 'part' },
|
||||||
|
PRD: { model: productModel, idField: '_id', type: 'product' },
|
||||||
|
VEN: { model: vendorModel, idField: '_id', type: 'vendor' },
|
||||||
|
SJB: { model: subJobModel, idField: '_id', type: 'subjob' },
|
||||||
|
FLS: { model: filamentStockModel, idField: '_id', type: 'filamentstock' },
|
||||||
|
SEV: { model: stockEventModel, idField: '_id', type: 'stockevent' },
|
||||||
|
SAU: { model: stockAuditModel, idField: '_id', type: 'stockaudit' },
|
||||||
|
PTS: { model: partStockModel, idField: '_id', type: 'partstock' },
|
||||||
|
PDS: { model: null, idField: '_id', type: 'productstock' }, // No productStockModel found
|
||||||
|
ADL: { model: auditLogModel, idField: '_id', type: 'auditlog' },
|
||||||
|
USR: { model: userModel, idField: '_id', type: 'user' },
|
||||||
|
NTY: { model: noteTypeModel, idField: '_id', type: 'notetype' },
|
||||||
|
NTE: { model: noteModel, idField: '_id', type: 'note' },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to build search filter from query parameters
|
||||||
|
const buildSearchFilter = (params) => {
|
||||||
|
const filter = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(params)) {
|
||||||
|
// Skip pagination and limit parameters as they're not search filters
|
||||||
|
if (key === 'limit' || key === 'page') continue;
|
||||||
|
|
||||||
|
// Handle different field types
|
||||||
|
if (key === 'name') {
|
||||||
|
filter.name = { $regex: value, $options: 'i' }; // Case-insensitive search
|
||||||
|
} else if (key === 'id' || key === '_id') {
|
||||||
|
if (mongoose.Types.ObjectId.isValid(value)) {
|
||||||
|
filter._id = value;
|
||||||
|
}
|
||||||
|
} else if (key === 'tags') {
|
||||||
|
filter.tags = { $in: [new RegExp(value, 'i')] };
|
||||||
|
} else if (key === 'state') {
|
||||||
|
filter['state.type'] = value;
|
||||||
|
} else if (key.includes('.')) {
|
||||||
|
// Handle nested fields like 'state.type', 'address.city', etc.
|
||||||
|
filter[key] = { $regex: value, $options: 'i' };
|
||||||
|
} else {
|
||||||
|
// For all other fields, do a case-insensitive search
|
||||||
|
filter[key] = { $regex: value, $options: 'i' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
const trimSpotlightObject = (object) => {
|
||||||
|
return {
|
||||||
|
_id: object._id,
|
||||||
|
name: object.name || undefined,
|
||||||
|
state: object.state && object?.state.type? { type: object.state.type } : undefined,
|
||||||
|
tags: object.tags || undefined,
|
||||||
|
email: object.email || undefined,
|
||||||
|
color: object.color || undefined,
|
||||||
|
updatedAt: object.updatedAt || undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getSpotlightRouteHandler = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const query = req.params.query;
|
||||||
|
const queryParams = req.query;
|
||||||
|
if (query.length < 3) {
|
||||||
|
res.status(200).send([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const prefix = query.substring(0, 3);
|
||||||
|
const delimiter = query.substring(3, 4);
|
||||||
|
const suffix = query.substring(4);
|
||||||
|
|
||||||
|
if (delimiter == ":") {
|
||||||
|
const prefixEntry = PREFIX_MODEL_MAP[prefix];
|
||||||
|
if (!prefixEntry || !prefixEntry.model) {
|
||||||
|
res.status(400).send({ error: "Invalid or unsupported prefix" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { model, idField } = prefixEntry;
|
||||||
|
|
||||||
|
// Validate ObjectId if the idField is '_id'
|
||||||
|
if (idField === '_id' && !mongoose.Types.ObjectId.isValid(suffix)) {
|
||||||
|
res.status(404).send({ error: `${prefix} not found` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the object by the correct field
|
||||||
|
const queryObj = {};
|
||||||
|
queryObj[idField] = suffix.toLowerCase();
|
||||||
|
let doc = await model.findOne(queryObj).lean();
|
||||||
|
if (!doc) {
|
||||||
|
res.status(404).send({ error: `${prefix} not found` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Build the response with only the required fields
|
||||||
|
const response = trimSpotlightObject(doc)
|
||||||
|
res.status(200).send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(queryParams)
|
||||||
|
|
||||||
|
if (Object.keys(queryParams).length > 0) {
|
||||||
|
const prefixEntry = PREFIX_MODEL_MAP[prefix];
|
||||||
|
console.log(prefixEntry)
|
||||||
|
if (!prefixEntry || !prefixEntry.model) {
|
||||||
|
res.status(400).send({ error: "Invalid or unsupported prefix" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { model } = prefixEntry;
|
||||||
|
|
||||||
|
// Use req.query for search parameters
|
||||||
|
|
||||||
|
if (Object.keys(queryParams).length === 0) {
|
||||||
|
res.status(400).send({ error: "No search parameters provided" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build search filter
|
||||||
|
const searchFilter = buildSearchFilter(queryParams);
|
||||||
|
|
||||||
|
// Perform search with limit
|
||||||
|
const limit = parseInt(req.query.limit) || 10;
|
||||||
|
const docs = await model.find(searchFilter)
|
||||||
|
.limit(limit)
|
||||||
|
.sort({ updatedAt: -1 })
|
||||||
|
.lean();
|
||||||
|
|
||||||
|
// Format response
|
||||||
|
const response = docs.map(doc => (trimSpotlightObject(doc)));
|
||||||
|
|
||||||
|
res.status(200).send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error in spotlight lookup:", error);
|
||||||
|
res.status(500).send({ error: error });
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { gcodeFileModel } from "../../schemas/gcodefile.schema.js";
|
import { gcodeFileModel } from "../../schemas/production/gcodefile.schema.js";
|
||||||
import { filamentModel } from "../../schemas/filament.schema.js";
|
import { filamentModel } from "../../schemas/management/filament.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
@ -9,7 +9,7 @@ import path from "path";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
import { extractConfigBlock } from "../../util/index.js";
|
import { extractConfigBlock } from "../../util/index.js";
|
||||||
|
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { jobModel } from "../../schemas/job.schema.js";
|
import { jobModel } from "../../schemas/production/job.schema.js";
|
||||||
import { subJobModel } from "../../schemas/subjob.schema.js";
|
import { subJobModel } from "../../schemas/production/subjob.schema.js";
|
||||||
import { noteModel } from "../../schemas/note.schema.js";
|
import { noteModel } from "../../schemas/misc/note.schema.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { printerModel } from "../../schemas/printer.schema.js";
|
import { printerModel } from "../../schemas/production/printer.schema.js";
|
||||||
import log4js from "log4js";
|
import log4js from "log4js";
|
||||||
import { newAuditLog } from "../../util/index.js";
|
import { newAuditLog } from "../../util/index.js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { auditLogModel } from "../../schemas/auditlog.schema.js";
|
import { auditLogModel } from "../../schemas/management/auditlog.schema.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ function getChangedValues(oldObj, newObj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function newAuditLog(oldValue, newValue, targetId, targetModel, ownerId, ownerModel) {
|
async function newAuditLog(oldValue, newValue, targetId, targetModel, ownerId, ownerModel) {
|
||||||
const { auditLogModel } = await import('../schemas/auditlog.schema.js');
|
const { auditLogModel } = await import('../schemas/management/auditlog.schema.js');
|
||||||
|
|
||||||
// Get only the changed values
|
// Get only the changed values
|
||||||
const changedValues = getChangedValues(oldValue, newValue);
|
const changedValues = getChangedValues(oldValue, newValue);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user