added to item for POV

This commit is contained in:
kukulaka
2020-09-03 03:49:30 +01:00
parent 728e756b59
commit 190bd6923e
3 changed files with 12 additions and 9 deletions

View File

@@ -77,7 +77,7 @@ app.use('/auth', authRouter)
.use('/fields', fieldsRouter)
.use('/files', filesRouter)
.use('/folders', foldersRouter)
.use('/items', itemsRouter)
.use('/items', itemsRouter, responseManager)
.use('/permissions', permissionsRouter)
.use('/presets', presetsRouter)
.use('/relations', relationsRouter)

View File

@@ -29,7 +29,7 @@ router.get(
'/:collection',
collectionExists,
sanitizeQuery,
asyncHandler(async (req, res) => {
asyncHandler(async (req, res, next) => {
const service = new ItemsService(req.collection, { accountability: req.accountability });
const metaService = new MetaService({ accountability: req.accountability });
@@ -39,10 +39,12 @@ router.get(
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
return res.json({
res.locals.data = {
meta: meta,
data: records || null,
});
};
return next();
})
);
@@ -50,7 +52,7 @@ router.get(
'/:collection/:pk',
collectionExists,
sanitizeQuery,
asyncHandler(async (req, res) => {
asyncHandler(async (req, res, next) => {
if (req.singleton) {
throw new RouteNotFoundException(req.path);
}
@@ -58,10 +60,11 @@ router.get(
const service = new ItemsService(req.collection, { accountability: req.accountability });
const primaryKey = req.params.pk.includes(',') ? req.params.pk.split(',') : req.params.pk;
const result = await service.readByKey(primaryKey as any, req.sanitizedQuery);
return res.json({
res.locals.data = {
data: result || null,
});
};
return next();
})
);

View File

@@ -33,7 +33,7 @@ const responseManager: RequestHandler = asyncHandler(async (req, res, next) => {
const fieldsOut = Object.keys(exportData);
const csv = await json2csv.parse(exportData, fieldsOut);
// will this be ok for larger files?
res.setHeader('Content-disposition', 'attachment; filename=export.csv');
res.set('Content-Type', 'text/csv');
res.status(200).send(csv);