Skip to content

Commit

Permalink
fix: product id should be required for replies too
Browse files Browse the repository at this point in the history
  • Loading branch information
karimdaghari committed Feb 13, 2020
1 parent 0b8a41d commit 22c6ea6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Comment {
id: ID!
postedAt: DateTime!
content: String!
productId: ID
productId: ID!
parentId: ID
replies: [Comment]
userId: ID!
Expand Down
6 changes: 3 additions & 3 deletions src/modules/comment/comment.entitiy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class Comment extends BaseEntity {
}
)
product!: Product;
@Field(() => ID, { nullable: true })
@Column({ nullable: true })
productId?: number;
@Field(() => ID)
@Column()
productId!: number;

@ManyToOne(
type => Comment,
Expand Down
6 changes: 4 additions & 2 deletions src/modules/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class CommentService {
parentId?: number
): Promise<Comment> {
if (parentId) {
return await this.addReply(parentId, content, userId);
return await this.addReply(parentId, content, userId, productId);
}

const newComment = new Comment();
Expand All @@ -88,12 +88,14 @@ export class CommentService {
private async addReply(
parentId: number,
content: string,
userId: number
userId: number,
productId: number
): Promise<Comment> {
const reply = new Comment();
reply.parentId = parentId;
reply.content = content;
reply.userId = userId;
reply.productId = productId;
const newReply = await this.commentRepository.save(reply);
const { parent } = await this.commentRepository.findOneOrFail(
{ id: newReply.id },
Expand Down

0 comments on commit 22c6ea6

Please sign in to comment.