Skip to content
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

Open
wants to merge 42 commits into
base: feat/announcement-function
Choose a base branch
from

Conversation

WNomunomu
Copy link
Contributor

@WNomunomu WNomunomu commented Apr 12, 2024

タスク

https://redmine.weseek.co.jp/issues/134084
https://redmine.weseek.co.jp/issues/134085

概要

  • announcementを作成、永続化できるようにしました。
  • announcementからinappnotificationを作成、永続化できるようにしました。

変更点

  • announcementを作成し、dbに保存するapiの実装
  • 作成したapiをクライアントサイドから叩くための関数の実装

セルフチェック

  • コンフリクト解消したか
  • 余計なコードは残っていないか
  • 適切にメモ化したか
  • 責務の問題はクリアしているか
  • CIは通っているか
  • PRの内容は適切にかけているか

@WNomunomu WNomunomu changed the base branch from master to feat/announcement-function April 12, 2024 08:09
@WNomunomu WNomunomu changed the base branch from feat/announcement-function to master May 24, 2024 00:08
Copy link

changeset-bot bot commented May 27, 2024

⚠️ No Changeset found

Latest commit: 45e69ac

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

reg-suit bot commented May 27, 2024

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.

@WNomunomu WNomunomu changed the base branch from master to feat/announcement-function June 23, 2024 06:49

const loginRequiredStrictly = require('~/server/middlewares/login-required')(crowi);

router.post('/', loginRequiredStrictly, async(req: CrowiRequest) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • pageId は req.params で取れる方が良さそう
  • express-valudator を使ってバリデーションもする

apps/app/src/server/routes/apiv3/announcement.ts Outdated Show resolved Hide resolved
apps/app/src/client/util/announcement-utils.ts Outdated Show resolved Hide resolved
apps/app/src/server/service/announcement.ts Outdated Show resolved Hide resolved
@WNomunomu WNomunomu changed the base branch from feat/announcement-function to master August 5, 2024 12:00
@WNomunomu WNomunomu changed the base branch from master to feat/announcement-function August 5, 2024 12:01
apps/app/src/server/routes/apiv3/announcement.ts Outdated Show resolved Hide resolved

const params: ParamsForAnnouncement = req.body;

const page = await Page.findById(params.pageId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req.paramsではpageIdが正しく取得できなかったため、この形にしています。

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/:id を用いることで、pageIdをパスパラメータで取得できるようにしました。


const params: ParamsForAnnouncement = req.body;

const page = await Page.findById(params.pageId);
Copy link
Member

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

apps/app/src/server/routes/apiv3/announcement.ts Outdated Show resolved Hide resolved
apps/app/src/interfaces/announcement.ts Outdated Show resolved Hide resolved
body('isReadReceiptTrackingEnabled').exists().isBoolean(),
body('pageId').exists({ checkFalsy: true }),
body('receivers').exists({ checkFalsy: true }).isArray(),
],
Copy link
Member

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() をつけよう

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ごめん、そもそも req.body で pageId をとっているのであればそれを使うでよさそう

Copy link
Contributor Author

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);
Copy link
Member

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL は kebab-case で

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExternalAccountService を参考に、singleton instance をこのモジュールで export するようにしてください

Copy link
Contributor Author

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);
Copy link
Member

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


const pageId = params.pageId;

const page = await Page.findById(pageId);
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as を使わず記述してください

Copy link
Contributor Author

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> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private を付けよう

Copy link
Contributor Author

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは現存する何かしらのバグの修正?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants