Skip to content

Commit

Permalink
feat: add onlyTokenizedProjects filter
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 29, 2023
1 parent c7402c6 commit 0592f97
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const findAll = async (req, res) => {
projectIds,
filter,
order,
onlyMarketplaceProjects,
} = req.query;

let where = orgUid != null && orgUid !== 'all' ? { orgUid } : undefined;
Expand Down Expand Up @@ -209,6 +210,18 @@ export const findAll = async (req, res) => {
};
}

if (onlyMarketplaceProjects) {
if (!where) {
where = {};
}

const marketplaceProjectIds = await Project.getTokenizedProjectIds();

where.warehouseProjectId = {
[Sequelize.Op.in]: _.flatten([marketplaceProjectIds]),
};
}

const query = {
...columnsToInclude(columns, includes),
...pagination,
Expand Down
21 changes: 21 additions & 0 deletions src/models/projects/projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ class Project extends Model {
return upsertResult;
}

static async getTokenizedProjectIds() {
const sqlQuery = `
SELECT Projects.warehouseProjectId
FROM Projects
INNER JOIN Issuances ON Projects.warehouseProjectId = Issuances.warehouseProjectId
INNER JOIN Units ON Issuances.id = Units.issuanceId
WHERE Units.marketplaceIdentifier IS NOT NULL AND Units.marketplaceIdentifier != '';
`;

try {
const results = await sequelize.query(sqlQuery, {
type: sequelize.QueryTypes.SELECT,
});
return results.map((row) => row.warehouseProjectId);
} catch (error) {
// Handle errors
console.error(error);
throw error;
}
}

static async fts(searchStr, orgUid, pagination, columns = []) {
const dialect = sequelize.getDialect();

Expand Down
1 change: 1 addition & 0 deletions src/validations/projects.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const projectsGetQuerySchema = Joi.object()
projectIds: Joi.array().items(Joi.string()).single(),
order: Joi.string().regex(genericSortColumnRegex),
filter: Joi.string().regex(genericFilterRegex),
onlyMarketplaceProjects: Joi.boolean(),
})
.with('page', 'limit')
.with('limit', 'page');
Expand Down

0 comments on commit 0592f97

Please sign in to comment.