-
-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathrecipe.type.ts
More file actions
28 lines (24 loc) · 709 Bytes
/
Copy pathrecipe.type.ts
File metadata and controls
28 lines (24 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Field, Float, Int, ObjectType } from "type-graphql";
@ObjectType()
export class Recipe {
/* By default, every field gets a complexity of 1 */
@Field()
title!: string;
/* Which can be customized by passing the complexity parameter */
@Field(_type => Int, { complexity: 2 })
ratingsCount!: number;
@Field(_type => Float, {
nullable: true,
complexity: 10,
})
get averageRating(): number | null {
const ratingsCount = this.ratings.length;
if (ratingsCount === 0) {
return null;
}
const ratingsSum = this.ratings.reduce((a, b) => a + b, 0);
return ratingsSum / ratingsCount;
}
// Internal property, not exposed in schema
ratings!: number[];
}