test again

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-13 12:46:38 +08:00
parent e5e2580c7d
commit f5254f7571
12 changed files with 441 additions and 461 deletions
+13 -3
View File
@@ -1,5 +1,5 @@
// utils/paginate.util.js
const { Sequelize } = require('sequelize');
const { Sequelize, Op } = require('sequelize');
const { modelToAttributes } = require('./modelToAttributes.util');
const { excludeJsonbPaths } = require('./excludeJSONBPaths.util');
const { buildQuery } = require('./buildQuery.util');
@@ -108,7 +108,10 @@ async function paginate(model, req, {
const ALLOWED_FIELDS = attributes.map((a) => a.field);
const computedFieldKeys = computedAttributes.map((c) => c.key);
const { where, order } = buildQuery(filters, sort, ALLOWED_FIELDS, computedFieldKeys);
// Sequelize aliases the main model's table with the model's name by default
// (e.g. `FROM "users" AS "User"`) — needed to qualify Sequelize.col()
// references so they don't collide with same-named columns on joined tables.
const { where, order } = buildQuery(filters, sort, ALLOWED_FIELDS, computedFieldKeys, model.name);
// Build attribute includes: jsonb + audit subqueries + any extra from findOptions
const baseIncludes = jsonbAttr ? [jsonbAttr] : [];
@@ -131,9 +134,16 @@ async function paginate(model, req, {
const { attributes: _attr, ...restFindOptions } = findOptions;
// Nest rather than shallow-spread — `where` and `restFindOptions.where` can
// both carry an [Op.and] key (the same global Symbol), and spreading two
// objects that share a Symbol key silently drops the first one's value.
const combinedWhere = restFindOptions.where
? { [Op.and]: [where, restFindOptions.where] }
: where;
const { count, rows } = await model.findAndCountAll({
...restFindOptions,
where: { ...where, ...(restFindOptions.where ?? {}) },
where: combinedWhere,
order,
limit,
offset,