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 fs = require("fs");
const csv = require("csv-parser"); const csv = require("csv-parser");
const path = require("path"); const path = require("path");
const UnitMaster = db.UnitMaster;
exports.createProduct = async (req, res) => { exports.createProduct = async (req, res) => {
try { try {
@ -20,7 +20,15 @@ exports.createProduct = async (req, res) => {
exports.getAllProducts = async (req, res) => { exports.getAllProducts = async (req, res) => {
try { 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 }); res.status(200).send({'status':"success",'message':"Fetched successfully",'data': data });

View File

@ -1,4 +1,6 @@
const db = require("../models"); const db = require("../models");
const { Op } = require("sequelize");
const { Sequelize } = require("sequelize");
const QuarterlyWindowsConfiguration = db.QuarterlyWindowsConfiguration; const QuarterlyWindowsConfiguration = db.QuarterlyWindowsConfiguration;
// Create new configuration // Create new configuration
@ -19,6 +21,17 @@ exports.createConfig = async (req, res) => {
exports.getAllConfigs = async (req, res) => { exports.getAllConfigs = async (req, res) => {
try { try {
const data = await QuarterlyWindowsConfiguration.findAll({ 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"]], order: [["year", "DESC"]],
}); });
res 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"); const { UnitMaster } = require("../models");
// Create new Unit // Create new Unit
@ -14,13 +16,27 @@ exports.createUnit = async (req, res) => {
// Get all Units // Get all Units
exports.getAllUnits = async (req, res) => { exports.getAllUnits = async (req, res) => {
try { 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 }); res.status(200).json({ status: "success", data: units });
} catch (err) { } catch (err) {
res.status(500).json({ status: "error", message: err.message }); res.status(500).json({ status: "error", message: err.message });
} }
}; };
// Get Unit by ID // Get Unit by ID
exports.getUnitById = async (req, res) => { exports.getUnitById = async (req, res) => {
try { try {

View File

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

View File

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

View File

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