Skip to content

Commit

Permalink
feat: add exception case for AI
Browse files Browse the repository at this point in the history
  • Loading branch information
letronghoangminh committed Jun 11, 2023
1 parent bb9f113 commit 3f48fc1
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,16 +1190,22 @@ export class UserService {

const potentialUserIds = potentialUsers.map((user) => user.id);

const response = await axios.post(
`${this.recommendationSystemRoot}/match?user_id=${user.id}`,
potentialUserIds,
);
let recommendedUserIds: number[];

try {
const response = await axios.post(
`${this.recommendationSystemRoot}/match?user_id=${user.id}`,
potentialUserIds,
);

const recommendationData: number[] = JSON.parse(
JSON.stringify(response.data),
)['rank_list'];
const recommendationData: number[] = JSON.parse(
JSON.stringify(response.data),
)['rank_list'];

const recommendedUserIds = recommendationData.slice(0, query.quantity);
recommendedUserIds = recommendationData.slice(0, query.quantity);
} catch (err) {
recommendedUserIds = potentialUserIds;
}

const recommendedUsers = await this.prismaService.user.findMany({
where: {
Expand Down Expand Up @@ -1314,16 +1320,22 @@ export class UserService {

const potentialUserIds = potentialUsers.map((user) => user.id);

const response = await axios.post(
`${this.recommendationSystemRoot}/match?user_id=${user.id}`,
potentialUserIds,
);
let recommendedUserIds: number[];

try {
const response = await axios.post(
`${this.recommendationSystemRoot}/match?user_id=${user.id}`,
potentialUserIds,
);

const recommendationData: number[] = JSON.parse(
JSON.stringify(response.data),
)['rank_list'];
const recommendationData: number[] = JSON.parse(
JSON.stringify(response.data),
)['rank_list'];

const recommendedUserIds = recommendationData.slice(0, 1);
recommendedUserIds = recommendationData.slice(0, 1);
} catch (error) {
recommendedUserIds = potentialUserIds;
}

const recommendedUser = await this.prismaService.user.findFirst({
where: {
Expand Down

0 comments on commit 3f48fc1

Please sign in to comment.