Skip to content

Commit

Permalink
Merge pull request #236 from Roger13579/fix/group-detail-vacancy
Browse files Browse the repository at this point in the history
fix: add vacancy at groupDetail
  • Loading branch information
Roger13579 authored Jun 17, 2024
2 parents 205a50a + ecf19e6 commit 90345fa
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/service/groupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { UserRepository } from '../repository/userRepository';
import { Types } from 'mongoose';
import { LeaveGroupDto } from '../dto/group/leaveGroupDto';
import { GroupFilterDto } from '../dto/group/groupFilterDto';
import { GroupDocument } from '../types/group.type';

const logger = log4js.getLogger(`GroupService`);

Expand Down Expand Up @@ -148,6 +149,21 @@ export class GroupService {
}

public async findGroupDetail(groupId: string) {
return await this.groupRepository.findById(new Types.ObjectId(groupId));
const group = await this.groupRepository.findById(
new Types.ObjectId(groupId),
);
if (group) {
const participantLength =
group.participant != undefined ? group.participant.length : 0;
return {
...group.toObject(),
vacancy: group.amount - participantLength,
} as GroupDocument;
} else {
throwError(
CustomResponseType.NO_DATA_FOUND_MESSAGE + ` : ${groupId}`,
CustomResponseType.NO_DATA_FOUND,
);
}
}
}

0 comments on commit 90345fa

Please sign in to comment.