Skip to content

Commit

Permalink
fix: グループを作成日順に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
nacika-ins committed May 10, 2024
1 parent 63cd918 commit 1db7a53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
27 changes: 17 additions & 10 deletions packages/backend/src/server/api/endpoints/users/groups/joined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private userGroupEntityService: UserGroupEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const ownedGroups = await this.userGroupsRepository.findBy({
userId: me.id,
});

const joinings = await this.userGroupJoiningsRepository.findBy({
userId: me.id,
...(ownedGroups.length > 0 ? {
userGroupId: Not(In(ownedGroups.map(x => x.id))),
} : {}),
});
const ownedGroups = await this.userGroupsRepository.find({
where: {
userId: me.id,
},
order: {
createdAt: 'DESC',
},
});

const joinings = await this.userGroupJoiningsRepository.find({ where: {
userId: me.id,
...(ownedGroups.length > 0 ? {
userGroupId: Not(In(ownedGroups.map(x => x.id))),
} : {}),
}, order: {
createdAt: 'DESC',
} });

return await Promise.all(joinings.map(x => this.userGroupEntityService.pack(x.userGroupId)));
});
Expand Down
11 changes: 8 additions & 3 deletions packages/backend/src/server/api/endpoints/users/groups/owned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private userGroupEntityService: UserGroupEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const userGroups = await this.userGroupsRepository.findBy({
userId: me.id,
});
const userGroups = await this.userGroupsRepository.find({
where: {
userId: me.id,
},
order: {
createdAt: 'DESC',
},
});

return await Promise.all(userGroups.map(x => this.userGroupEntityService.pack(x)));
});
Expand Down

0 comments on commit 1db7a53

Please sign in to comment.