Changeset View
Changeset View
Standalone View
Standalone View
src/app/_models/post.ts
import { Author } from './author'; | import { Author } from './author'; | ||||
import { Comment } from './comment'; | import { Comment } from './comment'; | ||||
import { Image } from './image'; | import { Image } from './image'; | ||||
export class Post { | export class Post { | ||||
public created: Date; | |||||
static parse(obj: any) { | static parse(obj: any) { | ||||
return new Post( | return new Post( | ||||
obj.id, | obj.id, | ||||
(() => { | (() => { | ||||
if (obj.author === null) { | if (obj.author === null) { | ||||
return new Author(498, 'Anonymous', 'https://static.wildfyre.net/anonym.svg', null, false); | return new Author(498, 'Anonymous', 'https://static.wildfyre.net/anonym.svg', null, false); | ||||
} | } | ||||
return Author.parse(obj.author); | return Author.parse(obj.author); | ||||
Show All 26 Lines | static parse(obj: any) { | ||||
); | ); | ||||
} | } | ||||
constructor( | constructor( | ||||
public id: number, | public id: number, | ||||
public author: Author, | public author: Author, | ||||
public anonym: boolean, | public anonym: boolean, | ||||
public subscribed: boolean, | public subscribed: boolean, | ||||
created: string, | public created: string, | ||||
public active: boolean, | public active: boolean, | ||||
public text: string, | public text: string, | ||||
public image: string, | public image: string, | ||||
public additional_images: Image[], | public additional_images: Image[], | ||||
public comments: Comment[] | public comments: Comment[] | ||||
) { | ) { | ||||
this.created = new Date(created); | const options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' }; | ||||
const time = new Date(created); | |||||
this.created = time.toLocaleDateString(undefined, options); | |||||
} | } | ||||
getError(): PostError { | getError(): PostError { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
export class PostError extends Post { | export class PostError extends Post { | ||||
Show All 11 Lines |