Commit bd620f1ead2bd73d27ccb41b8b368393c7cf9f09
1 parent
4d13ee9f
fix: form stat api 500; (zh) 修正表单统计接口无法获取数据
Showing
1 changed file
with
5 additions
and
8 deletions
back-end/h5-api/api/work/controllers/Work.js
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | * @Author: ly525 |
| 3 | 3 | * @Date: 2019-12-04 19:55:24 |
| 4 | 4 | * @LastEditors : ly525 |
| 5 | - * @LastEditTime : 2019-12-21 19:32:05 | |
| 5 | + * @LastEditTime : 2020-01-01 18:42:41 | |
| 6 | 6 | * @FilePath: /luban-h5/back-end/h5-api/api/work/controllers/Work.js |
| 7 | 7 | * @Github: https://github.com/ly525/luban-h5 |
| 8 | 8 | * @Description: |
| ... | ... | @@ -53,17 +53,14 @@ module.exports = { |
| 53 | 53 | const work = await strapi.services.work.findOne(ctx.params); |
| 54 | 54 | |
| 55 | 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 | 58 | const uuidMap2Name = getUuidMap2Name(work); |
| 62 | 59 | // eslint-disable-next-line require-atomic-updates |
| 63 | 60 | return ctx.body = { uuidMap2Name, formRecords }; |
| 64 | 61 | }, |
| 65 | 62 | queryWorksWithForms: async (ctx) => { |
| 66 | - let formRecords = await strapi.services.workform.fetchAll({ | |
| 63 | + let formRecords = await strapi.query('workform').model.fetchAll({ | |
| 67 | 64 | withRelated: [ |
| 68 | 65 | {'work': qb => qb.column('id') } |
| 69 | 66 | ], |
| ... | ... | @@ -72,12 +69,12 @@ module.exports = { |
| 72 | 69 | formRecords = formRecords.toJSON(); |
| 73 | 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 | 73 | columns: ['id', 'title'] |
| 77 | 74 | }); |
| 78 | 75 | workRecords = workRecords.toJSON().map(work => ({ |
| 79 | 76 | ...work, |
| 80 | - form_count: groupedFormRecords[work.id].length | |
| 77 | + form_count: groupedFormRecords[work.id] && groupedFormRecords[work.id].length | |
| 81 | 78 | })).filter(work => work.form_count); |
| 82 | 79 | |
| 83 | 80 | return ctx.body = workRecords; | ... | ... |