Skip to content

Commit

Permalink
fix(salary) - fix file upload (#340)
Browse files Browse the repository at this point in the history
* find salary fields dynamically from xlsx file
  • Loading branch information
nandinboldn committed Mar 18, 2024
1 parent 9bbafa5 commit 5256b1f
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 140 deletions.
23 changes: 14 additions & 9 deletions packages/plugin-salary-api/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default {
permissions,

meta: {
permissions,
permissions
},

graphql: async () => {
return {
typeDefs: await typeDefs(),
resolvers: await resolvers(),
resolvers: await resolvers()
};
},

Expand All @@ -34,7 +34,7 @@ export default {
const requestInfo = {
secure: req.secure,
cookies: req.cookies,
headers: req.headers,
headers: req.headers
};

context.subdomain = subdomain;
Expand All @@ -52,7 +52,7 @@ export default {

const corsOptions = {
credentials: true,
origin: DOMAIN || 'http://localhost:3000',
origin: DOMAIN || 'http://localhost:3000'
};

app.use(cors(corsOptions));
Expand Down Expand Up @@ -80,9 +80,14 @@ export default {
}

try {
const result = await handleUpload(subdomain, req.user, file, title);

res.status(200).json({ success: true, result });
const message = await handleUpload(
subdomain,
req.user,
file,
title
);

res.status(200).json({ success: true, message });
} catch (e) {
return res.status(200).json({ error: e.message });
}
Expand All @@ -91,8 +96,8 @@ export default {
// next(e);
return res.status(200).json({ error: e.message });
}
},
}
);
},
setupMessageConsumers,
setupMessageConsumers
};
20 changes: 19 additions & 1 deletion packages/plugin-salary-api/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,23 @@ export const SALARY_FIELDS = [
'hhoat',
'otherDeduction',
'preliminarySalary',
'endSalary',
'endSalary'
];

export const SALARY_FIELDS_MAP = {
'ажилтны код': 'employeeId',
'ажиллавал зохих цаг': 'totalWorkHours',
'ажилласан цаг': 'totalWorkedHours',
'үндсэн цалин': 'mainSalary',
'олговол зохих цалин': 'adequateSalary',
'ээлжийн амралт': 'vacation',
'нийт нэмэгдэл': 'totalAddition',
'сарын kpi': 'kpi',
'бусад нэмэгдэл': 'otherAddition',
'бусад суутгал': 'otherDeduction',
'нийт суутгал': 'mainDeduction',
ндш: 'ndsh',
ххоат: 'hhoat',
'урьдчилгаа цалин': 'preliminarySalary',
'сарын сүүл цалин': 'endSalary'
};
28 changes: 13 additions & 15 deletions packages/plugin-salary-api/src/graphql/resolvers/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const salaryQueries = {
async salaryReport(_root, args: any, { models }: IContext) {
const { page = 1, perPage = 20, employeeId } = args;

console.log('ajajjajaj');

const qry: any = {};

if (employeeId) {
Expand All @@ -26,18 +24,18 @@ const salaryQueries = {
async salaryByEmployee(
_root,
args: { password: string; page: number; perPage: number },
{ models, user, subdomain }: IContext,
{ models, user, subdomain }: IContext
) {
const { password, page = 1, perPage = 20 } = args;
const employee = await sendCommonMessage({
subdomain,
serviceName: 'core',
action: 'users.findOne',
data: {
_id: user._id,
_id: user._id
},
isRPC: true,
defaultValue: null,
defaultValue: null
});

const checkPassword = await sendCommonMessage({
Expand All @@ -46,10 +44,10 @@ const salaryQueries = {
action: 'users.comparePassword',
data: {
password,
userPassword: employee.password,
userPassword: employee.password
},
isRPC: true,
defaultValue: false,
defaultValue: false
});

if (!checkPassword) {
Expand All @@ -58,11 +56,11 @@ const salaryQueries = {

const list = await paginate(
models.Salaries.find({ employeeId: employee.employeeId }),
{ page, perPage },
{ page, perPage }
);

const totalCount = await models.Salaries.find({
employeeId: employee.employeeId,
employeeId: employee.employeeId
}).countDocuments();

return { list, totalCount };
Expand All @@ -72,7 +70,7 @@ const salaryQueries = {
const labels: any = {};
const exclude = ['createdAt', 'createdBy'];

Object.keys(salarySchema.paths).forEach((path) => {
Object.keys(salarySchema.paths).forEach(path => {
if (
salarySchema.paths[path].options.label === undefined ||
exclude.includes(path)
Expand All @@ -89,7 +87,7 @@ const salaryQueries = {
const symbmols: any = {};
const exclude = ['createdAt', 'createdBy'];

Object.keys(salarySchema.paths).forEach((path) => {
Object.keys(salarySchema.paths).forEach(path => {
if (
salarySchema.paths[path].options.symbol === undefined ||
exclude.includes(path)
Expand All @@ -100,12 +98,12 @@ const salaryQueries = {
});

return symbmols;
},
}
};

// requireLogin(salaryQueries, 'salaryReport');
// requireLogin(salaryQueries, 'salaryByEmployee');
requireLogin(salaryQueries, 'salaryReport');
requireLogin(salaryQueries, 'salaryByEmployee');

// checkPermission(salaryQueries, 'salaryReport', 'showSalaries', []);
checkPermission(salaryQueries, 'salaryReport', 'showSalaries', []);

export default salaryQueries;
Loading

0 comments on commit 5256b1f

Please sign in to comment.