-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implementions of announcement creation function #8715
base: feat/announcement-function
Are you sure you want to change the base?
feat: implementions of announcement creation function #8715
Conversation
…ons-of-announcement-creation-function
…creation-function
…creation-function
|
reg-suit detected visual differences. Check this report, and review them. ⚪ What do the circles mean?The number of circles represent the number of changed images.🔴 : Changed items, ⚪ : New items, ⚫ : Deleted items, and 🔵 Passed items How can I change the check status?If reviewers approve this PR, the reg context status will be green automatically. |
…ons-of-announcement-creation-function
|
||
const params: ParamsForAnnouncement = req.body; | ||
|
||
const page = await Page.findById(params.pageId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req.paramsではpageIdが正しく取得できなかったため、この形にしています。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
クライアントのリクエスト方法がパスパラメーターで取得できるかたちになっていないのでは?
https://github.com/weseek/growi/pull/8715/files#diff-16e65c79c9018f437410fdf1211d572707905ec324e3b3129c795555aa364a5cR13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/:id を用いることで、pageIdをパスパラメータで取得できるようにしました。
…ons-of-announcement-creation-function
|
||
const params: ParamsForAnnouncement = req.body; | ||
|
||
const page = await Page.findById(params.pageId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
クライアントのリクエスト方法がパスパラメーターで取得できるかたちになっていないのでは?
https://github.com/weseek/growi/pull/8715/files#diff-16e65c79c9018f437410fdf1211d572707905ec324e3b3129c795555aa364a5cR13
…creation-function
…ons-of-announcement-creation-function
body('isReadReceiptTrackingEnabled').exists().isBoolean(), | ||
body('pageId').exists({ checkFalsy: true }), | ||
body('receivers').exists({ checkFalsy: true }).isArray(), | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- sender とか pageId など ObjectId でとるものは isMongoId() をつけよう
- バリデーションに失敗した時にクライアントにエラーメッセージを返却するために .withMessage() をつけよう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validatorに設定を追加させていただきました。
|
||
const params: ParamsForAnnouncement = req.body; | ||
|
||
const { id: pageId } = req.params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ごめん、そもそも req.body で pageId をとっているのであればそれを使うでよさそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req.bodyを採用しました。
await apiv3Post('/announcement/doAnnouncement', params); | ||
} | ||
catch (err) { | ||
toastError(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toastr の表示は view の責務
このユーティリティは DAO/サービス層に分類されるので不適切
], | ||
}; | ||
|
||
router.post('/doAnnouncement', loginRequiredStrictly, validators.doAnnouncement, async(req: CrowiRequest) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL は kebab-case で
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちら kebab-case にしました。
|
||
} | ||
|
||
module.exports = AnnouncementService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExternalAccountService を参考に、singleton instance をこのモジュールで export するようにしてください
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singleton instanceをexportするようにしました。
|
||
const activity = await crowi.activityService.createActivity(parametersForActivity); | ||
|
||
crowi.announcementService.doAnnounce(activity, page, params); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- announcementService は crowi 経由で取得するのではなくここで直接動的 import する
- try-catch してください
- エラーの場合はログ出力して 500 status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接動的 import する形に変更しました。
また、エラーの場合はログ出力、500 status を出すように変更しました。
|
||
const pageId = params.pageId; | ||
|
||
const page = await Page.findById(pageId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- req.user がアクセスできるページでないといけないので、取得はそれを考慮しているメソッドを使ってください
- ページが見つからなかった場合は 4xx 系エラーを返す
@@ -58,6 +55,12 @@ const AnnouncementSchema = new Schema<AnnouncementDocument>({ | |||
], | |||
}, {}); | |||
|
|||
AnnouncementSchema.statics.createByParameters = async function(parameters): Promise<IAnnouncement> { | |||
const announcement = await this.create(parameters) as IAnnouncement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as を使わず記述してください
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as を消去し、修正しました。
|
||
insertAnnouncement = async( | ||
params: ParamsForAnnouncement, | ||
): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private を付けよう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private method にしました。
}, | ||
}]; | ||
|
||
await Announcement.bulkWrite(operation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bulkWrite しないといけない理由ある?
props.push(...adminUsers); | ||
const { notificationTargetUsers } = props; | ||
|
||
notificationTargetUsers.push(...adminUsers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは現存する何かしらのバグの修正?
…creation-function
…creation-function
タスク
https://redmine.weseek.co.jp/issues/134084
https://redmine.weseek.co.jp/issues/134085
概要
変更点
セルフチェック