Skip to content

Commit

Permalink
feat: 課程上架時新增課程評分資料表
Browse files Browse the repository at this point in the history
  • Loading branch information
ankazu committed Jul 29, 2023
1 parent acc8c3f commit 6aada0a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions controllers/courseProviderController/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { User } = require('models/users')
const { checkUserExist } = require('src/utils/template')
const { errorTemplateFun } = require('src/utils/template')
const { URL_PREFIX, COURSE_PROVIDER_COVER_PHOTO_FOLDER_PREFIX } = require('src/js/url')
const { RatingSummary } = require('models/rating_summarys')

exports.courses = {
get: async (req, res) => {
Expand Down Expand Up @@ -265,6 +266,19 @@ exports.course = {
isPublish: true
})

let ratingSummary = await RatingSummary.findOne({
where: {
courseId: courseid
}
})

if (!ratingSummary) {
ratingSummary = await RatingSummary.create({
courseId: courseid,
avgRating: 0,
countRating: 0
})
}
if (result) {
res.json({
status: true,
Expand Down

0 comments on commit 6aada0a

Please sign in to comment.