This commit is contained in:
Gowtham M 2025-11-04 19:21:02 +05:30
parent 6724b13765
commit d98bcbc4c8
6 changed files with 79 additions and 8 deletions

View File

@ -3,7 +3,7 @@ const Product = db.Product;
const fs = require("fs");
const csv = require("csv-parser");
const path = require("path");
const UnitMaster = db.UnitMaster;
exports.createProduct = async (req, res) => {
try {
@ -20,7 +20,15 @@ exports.createProduct = async (req, res) => {
exports.getAllProducts = async (req, res) => {
try {
const data = await Product.findAll();
const data = await Product.findAll({
include: [
{
model: UnitMaster,
as: "unit",
attributes: ["uom"],
},
],
});
res.status(200).send({'status':"success",'message':"Fetched successfully",'data': data });

View File

@ -1,4 +1,6 @@
const db = require("../models");
const { Op } = require("sequelize");
const { Sequelize } = require("sequelize");
const QuarterlyWindowsConfiguration = db.QuarterlyWindowsConfiguration;
// Create new configuration
@ -19,6 +21,17 @@ exports.createConfig = async (req, res) => {
exports.getAllConfigs = async (req, res) => {
try {
const data = await QuarterlyWindowsConfiguration.findAll({
attributes: {
include: [
[
Sequelize.literal(`(
SELECT COUNT(*) FROM submission AS s
WHERE s.quarter = quarterly_windows_configuration_master.quarter AND s.year = quarterly_windows_configuration_master.year
)`),
"submission_count",
],
],
},
order: [["year", "DESC"]],
});
res

View File

@ -1,4 +1,6 @@
// controllers/unitMasterController.js
const db = require("../models");
const { Op } = require("sequelize");
const { Sequelize } = require("sequelize");
const { UnitMaster } = require("../models");
// Create new Unit
@ -14,13 +16,27 @@ exports.createUnit = async (req, res) => {
// Get all Units
exports.getAllUnits = async (req, res) => {
try {
const units = await UnitMaster.findAll();
const units = await UnitMaster.findAll({
attributes: {
include: [
[
Sequelize.literal(
`(SELECT COUNT(*) FROM products AS P WHERE P.unit_id = UnitMaster.id)`
),
"mapped_products_count",
],
],
},
logging: console.log
});
res.status(200).json({ status: "success", data: units });
} catch (err) {
res.status(500).json({ status: "error", message: err.message });
}
};
// Get Unit by ID
exports.getUnitById = async (req, res) => {
try {

View File

@ -17,6 +17,10 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.TEXT,
allowNull: true,
},
unit_id: {
type: DataTypes.INTEGER,
allowNull: true,
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: true,
@ -43,17 +47,22 @@ module.exports = (sequelize, DataTypes) => {
});
Product.associate = (models) => {
Product.hasMany(models.EstablishmentProduct, {
foreignKey: "product_id",
as: "establishment_products",
});
};
Product.associate = (models) => {
Product.hasMany(models.SubmissionProduct, {
foreignKey: "product_id",
as: "submission_products",
});
Product.belongsTo(models.UnitMaster, {
foreignKey: "unit_id",
as: "unit",
});
};
return Product;

View File

@ -7,6 +7,10 @@ module.exports = (sequelize, DataTypes) => {
autoIncrement: true,
primaryKey: true,
},
survey_name: {
type: DataTypes.STRING(10),
allowNull: false,
},
year: {
type: DataTypes.INTEGER,
allowNull: false,

View File

@ -917,6 +917,9 @@ router.delete("/establishment-users/:id",[verifySignature, verifyToken], establi
* hs_description:
* type: string
* example: "Portable automatic data processing machines"
* unit_id:
* type: integer
* example: "select data from unit master"
* is_active:
* type: boolean
* example: true
@ -987,10 +990,19 @@ router.get("/products/:id", [verifySignature, verifyToken],productController.get
* properties:
* product_name:
* type: string
* example: "Desktop Computer"
* example: "Laptop"
* hs_code:
* type: string
* example: "8471.30"
* hs_description:
* type: string
* example: "Portable automatic data processing machines"
* unit_id:
* type: integer
* example: "select data from unit master"
* is_active:
* type: boolean
* example: false
* example: true
* responses:
* 200:
* description: Product updated successfully
@ -2308,6 +2320,7 @@ router.put("/notification_templates/:id",[verifySignature, verifyToken], notific
* schema:
* type: object
* properties:
* survey_name: { type: string, example: "Test"}
* year: { type: integer }
* quarter: { type: string, example: "Q1" }
* start_date: { type: string, format: date }
@ -2373,6 +2386,14 @@ router.get("/quarterly_windows/:id",[verifySignature, verifyToken], quarterlyWin
* application/json:
* schema:
* type: object
* properties:
* survey_name: { type: string, example: "Test"}
* year: { type: integer }
* quarter: { type: string, example: "Q1" }
* start_date: { type: string, format: date }
* end_date: { type: string, format: date }
* grace_periods_days: { type: integer }
* is_active: { type: boolean }
* responses:
* 200:
* description: Updated successfully