AletheiaFact / AletheiaFact/aletheia

Refactor Badge Queries and Modify Schema for Mongoose `find` Usage

オープン
#1,111 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
tech
主要言語
TypeScript
スター
55
フォーク
20
平均マージ
2日 6時間
マージ済み PR(30日)
2

説明

## Background Information:

Currently, MongoDB aggregations are used to fetch data from the `BadgeModel` collection, and we want to transition to Mongoose find queries. The goal is to replace these aggregations with Mongoose `find` queries for improved readability and maintainability. Additionally, to enable the use of `find`, a `users` field needs to be added to the `Badge` schema, as the `User` schema already references badges, but the Badge schema lacks this reference.

## What:
Modify the Badge schema to include a `users` field and refactor the badge-related aggregation to use Mongoose `find` queries.

## How:

**Modify `Badge` Schema:**
- Add a `users` field to the Badge schema to establish a reference to the User schema.

```typescript
@Schema()
export class Badge {
// Existing properties...

@Prop({
type: [
{
type: mongoose.Types.ObjectId,
ref: "User",
required: false,
},
],
})
users: User[];
}
```

**Refactor Aggregation to Mongoose `find` Queries:**
- Rewrite the existing aggregation logic using Mongoose's find and populate methods.

```typescript
async listAll() {
return this.BadgeModel.find()
.populate({
path: 'users',
model: 'User',
select: '_id',
})
}
```

## Acceptance Criteria:

- [ ] Code Functionality: Verify that the modified Badge schema successfully establishes a reference to the User schema.
- [ ] Code Readability: Ensure that the refactored code is readable and adheres to best practices for Mongoose queries.
- [ ] Schema Modification: Confirm that the Badge schema includes the users field as described in the modification.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。