-
Notifications
You must be signed in to change notification settings - Fork 0
/
Book.ts
39 lines (33 loc) · 1.03 KB
/
Book.ts
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
29
30
31
32
33
34
35
36
37
38
39
import {Serializer, transform} from './Serializer'
import {SerializerHelper} from './SerializerHelper'
export class Author {
constructor(public firstName: string,
public lastName: string,
) {
}
}
export class Book implements Serializer<Book> {
constructor(public title: string,
public year: number,
public publisher: string,
public author: Author,
) {
}
public deserialize(data: any): Book {
const author = new Author(data.author.first_name, data.author.last_name)
return new Book(data.title, data.year, data.publisher, author)
}
@transform(SerializerHelper.upCase)
public serialize(data: Book): any {
console.log((data as any).test)
return {
title: data.title,
author_attributes: {
first_name: data.author.firstName,
last_name: data.author.lastName,
},
year: data.year,
publisher: data.publisher,
}
}
}