Return correct fields on /fields/:collection

This commit is contained in:
rijkvanzanten
2020-08-07 15:46:40 -04:00
parent a1b5dca17f
commit 9fb4d0e8eb
3 changed files with 12 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ router.get(
asyncHandler(async (req, res) => {
const service = new FieldsService({ accountability: req.accountability });
const fields = await service.readAll(req.collection);
const fields = await service.readAll(req.params.collection);
return res.json({ data: fields || null });
})
);
@@ -50,7 +50,7 @@ router.get(
const exists = await schemaInspector.hasColumn(req.collection, req.params.field);
if (exists === false) throw new FieldNotFoundException(req.collection, req.params.field);
const field = await service.readOne(req.collection, req.params.field);
const field = await service.readOne(req.params.collection, req.params.field);
return res.json({ data: field || null });
})
);

View File

@@ -100,7 +100,8 @@ router.post(
}
const record = await service.readByKey(keys as any, req.sanitizedQuery);
return res.json({ data: record || null });
return res.json({ data: res.locals.savedFiles.length === 1 ? record[0] : record || null });
})
);

View File

@@ -81,10 +81,16 @@ export default class FieldsService {
return data as Field;
});
let aliasFields = await this.knex
const aliasQuery = this.knex
.select<FieldMeta[]>('*')
.from('directus_fields')
.whereIn('special', ['alias', 'o2m']);
.whereIn('special', ['alias', 'o2m', 'm2m']);
if (collection) {
aliasQuery.andWhere('collection', collection);
}
let aliasFields = await aliasQuery;
aliasFields = (await this.payloadService.processValues('read', aliasFields)) as FieldMeta[];