This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from Uconnect-Technologies/v1.9.9
V1.9.9
- Loading branch information
Showing
17 changed files
with
343 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {get} from "lodash" | ||
import convertFiltersIntoSequalizeObject from "./convertFiltersIntoSequalizeObject"; | ||
import { request } from "express"; | ||
import { removeColumnsFromAccordingToSelectIgnoreFields } from "../../helpers/index"; | ||
export default async function (model) { | ||
return function (args, requestedFields: any = []) { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
if (!Array.isArray(requestedFields)) { | ||
console.error("Requested fields must be an array"); | ||
process.exit(); | ||
} | ||
let page = get(args, "pagination.page", 1); | ||
let limit = get(args, "pagination.limit", 10); | ||
let filters = get(args, "filters", {}); | ||
let sorting = get(args, "sorting", []); | ||
let offset = limit * (page - 1); | ||
let convertedFilters = await convertFiltersIntoSequalizeObject(filters); | ||
|
||
requestedFields = removeColumnsFromAccordingToSelectIgnoreFields( | ||
requestedFields, | ||
model.selectIgnoreFields | ||
); | ||
|
||
let mainObject = { | ||
order: sorting.map((c) => { | ||
return [c.column, c.type]; | ||
}), | ||
attributes: requestedFields, | ||
}; | ||
if (mainObject.attributes.length === 0) { | ||
delete mainObject["attributes"]; | ||
} | ||
if (mainObject.order.length == 0) { | ||
delete mainObject["order"]; | ||
} | ||
const list = await model.findAndCountAll({ | ||
offset: offset, | ||
limit: limit, | ||
where: convertedFilters, | ||
...mainObject, | ||
}); | ||
resolve({ | ||
filters, | ||
pagination: { page, limit }, | ||
list: list.rows, | ||
paginationProperties: { | ||
total: list.count, | ||
nextPage: page + 1, | ||
page: page, | ||
previousPage: page == 1 ? 1 : page - 1, | ||
pages: Math.ceil(list.count / limit), | ||
}, | ||
}); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { | ||
getQueryForLast7Days, | ||
getQueryForLastYear, | ||
getQueryForThisYear, | ||
getQueryForThisMonth, | ||
getQueryForLastMonth, | ||
getQueryForThisWeek, | ||
getQueryForToday, | ||
getQueryForLast90Days, | ||
} from "../../reporting/index"; | ||
import { get } from "lodash"; | ||
|
||
export default function (database, model) { | ||
return function (requestedReports) { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
let statsInfo = { | ||
total_count: null, | ||
total_created_today: null, | ||
total_created_this_week: null, | ||
total_created_last_7_days: null, | ||
total_created_this_month: null, | ||
total_created_last_month: null, | ||
total_created_last_90_days: null, | ||
total_created_last_year: null, | ||
total_created_this_year: null, | ||
}; | ||
let count, | ||
countLast7Days, | ||
countToday, | ||
countLastYear, | ||
countThisYear, | ||
countThisMonth, | ||
countThisweek, | ||
countLastMonth, | ||
countLast90Days; | ||
let selectOptions = { | ||
type: database.QueryTypes.SELECT, | ||
}; | ||
if (requestedReports.includes("total_count")) { | ||
count = await database.query( | ||
`select count(*) as total_count from ${model.getTableName()}`, | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_last_7_days")) { | ||
countLast7Days = await database.query( | ||
getQueryForLast7Days(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_today")) { | ||
countToday = await database.query( | ||
getQueryForToday(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_last_year")) { | ||
countLastYear = await database.query( | ||
getQueryForLastYear(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_this_year")) { | ||
countThisYear = await database.query( | ||
getQueryForThisYear(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_this_month")) { | ||
countThisMonth = await database.query( | ||
getQueryForThisMonth(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_this_week")) { | ||
countThisweek = await database.query( | ||
getQueryForThisWeek(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_last_month")) { | ||
countLastMonth = await database.query( | ||
getQueryForLastMonth(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
if (requestedReports.includes("total_created_last_90_days")) { | ||
countLast90Days = await database.query( | ||
getQueryForLast90Days(model.getTableName()), | ||
selectOptions | ||
); | ||
} | ||
|
||
statsInfo.total_count = get(count, "[0].total_count", 0); | ||
statsInfo.total_created_this_month = get( | ||
countThisMonth, | ||
"[0].total_created_this_month", | ||
0 | ||
); | ||
statsInfo.total_created_this_week = get( | ||
countThisweek, | ||
"[0].total_created_this_week", | ||
0 | ||
); | ||
statsInfo.total_created_last_7_days = get( | ||
countLast7Days, | ||
"[0].total_created_last_7_days", | ||
0 | ||
); | ||
statsInfo.total_created_today = get( | ||
countToday, | ||
"[0].total_created_today", | ||
0 | ||
); | ||
statsInfo.total_created_last_month = get( | ||
countLastMonth, | ||
"[0].total_created_last_month", | ||
0 | ||
); | ||
statsInfo.total_created_last_90_days = get( | ||
countLast90Days, | ||
"[0].total_created_last_90_days", | ||
0 | ||
); | ||
statsInfo.total_created_last_year = get( | ||
countLastYear, | ||
"[0].total_created_last_year", | ||
0 | ||
); | ||
statsInfo.total_created_this_year = get( | ||
countThisYear, | ||
"[0].total_created_this_year", | ||
0 | ||
); | ||
|
||
resolve(statsInfo); | ||
} catch (error) { | ||
reject(error) | ||
} | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.