Skip to content

Commit

Permalink
Merge pull request #5 from muraterzioglu/development
Browse files Browse the repository at this point in the history
Database, Bug & Logix Fix
  • Loading branch information
muraterzioglu authored Jan 17, 2022
2 parents b26b45b + 470e9a1 commit 4d89188
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
7 changes: 2 additions & 5 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Contents {
author: Author!

"""If it's a comment, define post here"""
relation: String
relation: Contents

"""Title of the content"""
title: String!
Expand All @@ -46,7 +46,7 @@ type Contents {
comments: [Contents!]!

"""All the reactions made by author"""
reactions: [Reaction!]!
reaction: [Reaction!]!
}

type Reaction {
Expand Down Expand Up @@ -86,9 +86,6 @@ input CreateAuthorInput {

"""E-Mail address of the author, should be unique"""
mail: String!

"""E-Mail address of the author, should be unique"""
avatar: String!
}

input CreateContentInput {
Expand Down
5 changes: 0 additions & 5 deletions src/authors/dto/create-author.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@ export class CreateAuthorInput {
description: 'E-Mail address of the author, should be unique',
})
mail: string;

@Field(() => String, {
description: 'E-Mail address of the author, should be unique',
})
avatar: string;
}
2 changes: 1 addition & 1 deletion src/authors/entities/author.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ObjectType, Field } from '@nestjs/graphql';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
@Entity('author')
@ObjectType()
export class Author {
@PrimaryGeneratedColumn('uuid')
Expand Down
3 changes: 2 additions & 1 deletion src/avatars/avatars.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class AvatarsService {
}

// Colors
const colorBg = seedColor(name).toHex();
// For seed generation we make the name lover case to prevent type errors like "JoHn DoE"
const colorBg = seedColor(name.toLocaleLowerCase()).toHex();
const colorFont = invertColor(colorBg);

// https://stackoverflow.com/questions/51568098/javascript-find-the-inverse-of-a-hex-code
Expand Down
15 changes: 14 additions & 1 deletion src/contents/contents.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ export class ContentsResolver {
return this.authorService.findOne(author);
}

@ResolveField('relation', () => Contents, {
description: 'Relation made for post',
})
async relation(@Parent() { id }: Contents): Promise<Contents> {
const content = await this.contentsService.findOne(id);
if (content.type == 'post') {
throw new HttpException(
"Forbidden Action: Posts can't have relation. relation is only accessible by comments",
HttpStatus.FORBIDDEN,
);
} else return content;
}

@ResolveField('comments', () => [Contents], {
description: 'All the comments made for post',
})
Expand All @@ -56,7 +69,7 @@ export class ContentsResolver {
} else return await this.contentsService.findPostComments(id);
}

@ResolveField('reactions', () => [Reaction], {
@ResolveField('reaction', () => [Reaction], {
description: 'All the reactions made by author',
})
async reactions(@Parent() { id }: Contents): Promise<Reaction[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/contents/entities/content.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Contents {
author: string;

@Column('uuid')
@Field(() => String, {
@Field(() => Contents, {
nullable: true,
description: "If it's a comment, define post here",
})
Expand Down

0 comments on commit 4d89188

Please sign in to comment.