Skip to content

Commit

Permalink
fix: update post created at when add post to experience (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 committed Feb 8, 2023
1 parent cec38d1 commit b368155
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/services/experience.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,35 @@ export class ExperienceService {
public async addPost(
data: CreateExperiencePostDto,
): Promise<ExperiencePost[]> {
const experiences = await this.experienceRepository.find({
where: {
createdBy: this.currentUser[securityId],
},
});

const experienceIds = experiences.map(e => String(e.id));
const newExperiencePosts = data.experienceIds.map(experienceId => {
return {
experienceId,
postId: data.postId,
};
});

return this.experiencePostRepository
.deleteAll({
experienceId: {inq: data.experienceIds},
experienceId: {inq: experienceIds},
postId: data.postId,
})
.then(() => {
const experiencePosts = data.experienceIds.map(experienceId => {
return new ExperiencePost({experienceId, postId: data.postId});
});

return this.experiencePostRepository.createAll(experiencePosts);
});
return Promise.all([
this.experiencePostRepository.createAll(newExperiencePosts),
this.postService.updateById(data.postId, {
createdAt: new Date().toString(),
updatedAt: new Date().toString(),
}),
]);
})
.then(([experiencePosts]) => experiencePosts);
}

public async substractPost(
Expand Down

0 comments on commit b368155

Please sign in to comment.