calculation logs api added
This commit is contained in:
parent
025b2bff07
commit
5891605545
@ -2,7 +2,7 @@ const db = require("../models");
|
|||||||
const logger = require("../services/logger");
|
const logger = require("../services/logger");
|
||||||
const IPICalculationService = require("../services/ipi_calculation_service");
|
const IPICalculationService = require("../services/ipi_calculation_service");
|
||||||
const SubmissionAutoFillService = require("../services/auto_fill_missing_quarterly_submissions_service");
|
const SubmissionAutoFillService = require("../services/auto_fill_missing_quarterly_submissions_service");
|
||||||
|
const CalculationLog = db.CalculationLog;
|
||||||
|
|
||||||
// Database configuration
|
// Database configuration
|
||||||
const dbConfig = {
|
const dbConfig = {
|
||||||
@ -287,6 +287,49 @@ exports.survey_auto_submit = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getCalculationLogsByYearMonth = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { year, month } = req.query;
|
||||||
|
|
||||||
|
if (!year) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: "Year is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!month) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: "Month is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const logs = await CalculationLog.findAll({
|
||||||
|
where: {
|
||||||
|
reference_year: year,
|
||||||
|
reference_month: month,
|
||||||
|
},
|
||||||
|
order: [["started_at", "DESC"]],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!logs.length) {
|
||||||
|
return res.status(404).json({
|
||||||
|
message: "No calculation logs found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
message: "Calculation logs fetched successfully",
|
||||||
|
data: logs,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(`Error getting calculation logs: ${err.message }`);
|
||||||
|
logger.error(`Stack trace: ${err.stack}`);
|
||||||
|
return res.status(500).json({
|
||||||
|
message: "Server error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1081,7 +1081,6 @@ exports.forgotPasswordRequestOTP = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const formattedSupportPhone = formatUAEPhoneNumber(process.env.SUPPORT_PHONE);
|
const formattedSupportPhone = formatUAEPhoneNumber(process.env.SUPPORT_PHONE);
|
||||||
// const formattedOtp = otp.split("").join(" ");
|
|
||||||
const placeHolderData = {
|
const placeHolderData = {
|
||||||
username: user.name,
|
username: user.name,
|
||||||
verfication_code: otp,
|
verfication_code: otp,
|
||||||
|
|||||||
47
app/models/calculation_log.model.js
Normal file
47
app/models/calculation_log.model.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
const CalculationLog = sequelize.define("calculation_log", {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
autoIncrement: true,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
calculation_type: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
reference_year: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
reference_month: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
records_processed: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
error_message: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
started_at: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: DataTypes.NOW,
|
||||||
|
},
|
||||||
|
completed_at: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
tableName: "calculation_log",
|
||||||
|
timestamps: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return CalculationLog;
|
||||||
|
};
|
||||||
@ -33,6 +33,7 @@ db.ManufacturingIpi = require("./manufacturingIPI.model.js")(sequelize, DataType
|
|||||||
db.Isic2DigitIndices = require("./isic2DigitIndices.model.js")(sequelize, DataTypes);
|
db.Isic2DigitIndices = require("./isic2DigitIndices.model.js")(sequelize, DataTypes);
|
||||||
db.Isic3DigitIndices = require("./isic3DigitIndices.model.js")(sequelize, DataTypes);
|
db.Isic3DigitIndices = require("./isic3DigitIndices.model.js")(sequelize, DataTypes);
|
||||||
db.Isic4DigitIndices = require("./isic4DigitIndices.model.js")(sequelize, DataTypes);
|
db.Isic4DigitIndices = require("./isic4DigitIndices.model.js")(sequelize, DataTypes);
|
||||||
|
db.CalculationLog = require("./calculation_log.model.js")(sequelize, DataTypes);
|
||||||
// Associations
|
// Associations
|
||||||
db.Establishment.hasMany(db.EstablishmentUser, {
|
db.Establishment.hasMany(db.EstablishmentUser, {
|
||||||
foreignKey: "establishment_id",
|
foreignKey: "establishment_id",
|
||||||
|
|||||||
@ -540,7 +540,6 @@ router.get("/testEmail", establishmentController.testEmail);
|
|||||||
* tags: [Establishments]
|
* tags: [Establishments]
|
||||||
* security:
|
* security:
|
||||||
* - appSignature: []
|
* - appSignature: []
|
||||||
* - CSRF: []
|
|
||||||
* cookieAuth: [] # or bearerAuth: [] if you use Authorization header
|
* cookieAuth: [] # or bearerAuth: [] if you use Authorization header
|
||||||
* requestBody:
|
* requestBody:
|
||||||
* required: true
|
* required: true
|
||||||
@ -3220,6 +3219,42 @@ router.post("/auth/request-otp",[verifySignature], establishmentController.reque
|
|||||||
*/
|
*/
|
||||||
router.post("/auth/verify-otp",[verifySignature], establishmentController.verifyOTPForLogin);
|
router.post("/auth/verify-otp",[verifySignature], establishmentController.verifyOTPForLogin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /api/calculation-log/getCalculationLogs:
|
||||||
|
* get:
|
||||||
|
* summary: Get calculation logs by reference year and month
|
||||||
|
* tags: [CalculationLog]
|
||||||
|
* security:
|
||||||
|
* - appSignature: []
|
||||||
|
* - CSRF: []
|
||||||
|
* cookieAuth: []
|
||||||
|
* parameters:
|
||||||
|
* - in: query
|
||||||
|
* name: year
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: integer
|
||||||
|
* example: 2025
|
||||||
|
* description: Reference year
|
||||||
|
* - in: query
|
||||||
|
* name: month
|
||||||
|
* required: true
|
||||||
|
* schema:
|
||||||
|
* type: integer
|
||||||
|
* example: 4
|
||||||
|
* description: Reference month (1-12)
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Calculation log details fetched successfully
|
||||||
|
* 400:
|
||||||
|
* description: Year and month are required
|
||||||
|
* 404:
|
||||||
|
* description: No records found
|
||||||
|
* 500:
|
||||||
|
* description: Server error
|
||||||
|
*/
|
||||||
|
router.get( "/calculation-log/getCalculationLogs", [verifySignature, verifyToken], calculationController.getCalculationLogsByYearMonth);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user