Commit bd620f1ead2bd73d27ccb41b8b368393c7cf9f09

Authored by ly525
1 parent 4d13ee9f

fix: form stat api 500; (zh) 修正表单统计接口无法获取数据

back-end/h5-api/api/work/controllers/Work.js
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 * @Author: ly525 2 * @Author: ly525
3 * @Date: 2019-12-04 19:55:24 3 * @Date: 2019-12-04 19:55:24
4 * @LastEditors : ly525 4 * @LastEditors : ly525
5 - * @LastEditTime : 2019-12-21 19:32:05 5 + * @LastEditTime : 2020-01-01 18:42:41
6 * @FilePath: /luban-h5/back-end/h5-api/api/work/controllers/Work.js 6 * @FilePath: /luban-h5/back-end/h5-api/api/work/controllers/Work.js
7 * @Github: https://github.com/ly525/luban-h5 7 * @Github: https://github.com/ly525/luban-h5
8 * @Description: 8 * @Description:
@@ -53,17 +53,14 @@ module.exports = { @@ -53,17 +53,14 @@ module.exports = {
53 const work = await strapi.services.work.findOne(ctx.params); 53 const work = await strapi.services.work.findOne(ctx.params);
54 54
55 // learn the query from: https://github.com/strapi/foodadvisor/blob/master/api/api/restaurant/controllers/Restaurant.js#L40 55 // 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 });
60 57
61 const uuidMap2Name = getUuidMap2Name(work); 58 const uuidMap2Name = getUuidMap2Name(work);
62 // eslint-disable-next-line require-atomic-updates 59 // eslint-disable-next-line require-atomic-updates
63 return ctx.body = { uuidMap2Name, formRecords }; 60 return ctx.body = { uuidMap2Name, formRecords };
64 }, 61 },
65 queryWorksWithForms: async (ctx) => { 62 queryWorksWithForms: async (ctx) => {
66 - let formRecords = await strapi.services.workform.fetchAll({ 63 + let formRecords = await strapi.query('workform').model.fetchAll({
67 withRelated: [ 64 withRelated: [
68 {'work': qb => qb.column('id') } 65 {'work': qb => qb.column('id') }
69 ], 66 ],
@@ -72,12 +69,12 @@ module.exports = { @@ -72,12 +69,12 @@ module.exports = {
72 formRecords = formRecords.toJSON(); 69 formRecords = formRecords.toJSON();
73 const groupedFormRecords = _.groupBy(formRecords, 'work.id'); 70 const groupedFormRecords = _.groupBy(formRecords, 'work.id');
74 71
75 - let workRecords = await strapi.services.work.fetchAll({ 72 + let workRecords = await strapi.query('work').model.fetchAll({
76 columns: ['id', 'title'] 73 columns: ['id', 'title']
77 }); 74 });
78 workRecords = workRecords.toJSON().map(work => ({ 75 workRecords = workRecords.toJSON().map(work => ({
79 ...work, 76 ...work,
80 - form_count: groupedFormRecords[work.id].length 77 + form_count: groupedFormRecords[work.id] && groupedFormRecords[work.id].length
81 })).filter(work => work.form_count); 78 })).filter(work => work.form_count);
82 79
83 return ctx.body = workRecords; 80 return ctx.body = workRecords;