Skip to content

Commit bd620f1

Browse files
committed
fix: form stat api 500; (zh) 修正表单统计接口无法获取数据
1 parent 4d13ee9 commit bd620f1

File tree

1 file changed

+5
-8
lines changed
  • back-end/h5-api/api/work/controllers

1 file changed

+5
-8
lines changed

back-end/h5-api/api/work/controllers/Work.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: ly525
33
* @Date: 2019-12-04 19:55:24
44
* @LastEditors : ly525
5-
* @LastEditTime : 2019-12-21 19:32:05
5+
* @LastEditTime : 2020-01-01 18:42:41
66
* @FilePath: /luban-h5/back-end/h5-api/api/work/controllers/Work.js
77
* @Github: https://github.com/ly525/luban-h5
88
* @Description:
@@ -53,17 +53,14 @@ module.exports = {
5353
const work = await strapi.services.work.findOne(ctx.params);
5454

5555
// learn the query from: https://github.com/strapi/foodadvisor/blob/master/api/api/restaurant/controllers/Restaurant.js#L40
56-
let formRecords = await strapi.services.workform.query(qb => {
57-
qb.where('work', '=', work.id);
58-
}).fetchAll();
59-
formRecords = formRecords.toJSON();
56+
let formRecords = await strapi.services.workform.find({ work: work.id });
6057

6158
const uuidMap2Name = getUuidMap2Name(work);
6259
// eslint-disable-next-line require-atomic-updates
6360
return ctx.body = { uuidMap2Name, formRecords };
6461
},
6562
queryWorksWithForms: async (ctx) => {
66-
let formRecords = await strapi.services.workform.fetchAll({
63+
let formRecords = await strapi.query('workform').model.fetchAll({
6764
withRelated: [
6865
{'work': qb => qb.column('id') }
6966
],
@@ -72,12 +69,12 @@ module.exports = {
7269
formRecords = formRecords.toJSON();
7370
const groupedFormRecords = _.groupBy(formRecords, 'work.id');
7471

75-
let workRecords = await strapi.services.work.fetchAll({
72+
let workRecords = await strapi.query('work').model.fetchAll({
7673
columns: ['id', 'title']
7774
});
7875
workRecords = workRecords.toJSON().map(work => ({
7976
...work,
80-
form_count: groupedFormRecords[work.id].length
77+
form_count: groupedFormRecords[work.id] && groupedFormRecords[work.id].length
8178
})).filter(work => work.form_count);
8279

8380
return ctx.body = workRecords;

0 commit comments

Comments
 (0)