You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
import { environment } from 'src/environments/environment'; |
|
|
|
import { Choice } from './choice.model'; |
|
import { Comment } from './comment.model'; |
|
import { PollConfiguration } from './configuration.model'; |
|
import { User } from './user.model'; |
|
|
|
export class Poll { |
|
constructor( |
|
public owner: User = new User(), |
|
public slug: string = 'default-slug', |
|
public title: string = 'default title', |
|
public description?: string, |
|
public configuration: PollConfiguration = new PollConfiguration(), |
|
public comments: Comment[] = [], |
|
public choices: Choice[] = [], |
|
public dateChoices: Choice[] = [], |
|
public timeChoices: Choice[] = [] |
|
) {} |
|
|
|
public getAdministrationUrl(): string { |
|
return `${environment.api.baseHref}/administration/polls/${this.slug}`; |
|
} |
|
|
|
public getParticipationUrl(): string { |
|
return `${environment.api.baseHref}/participation/polls/${this.slug}`; |
|
} |
|
|
|
public static adaptFromLocalJsonServer( |
|
item: Pick<Poll, 'owner' | 'title' | 'description' | 'slug' | 'configuration' | 'comments' | 'choices'> |
|
): Poll { |
|
return new Poll( |
|
new User(item.owner.pseudo, item.owner.email, undefined), |
|
item.slug, |
|
item.title, |
|
item.description, |
|
item.configuration, |
|
item.comments |
|
.map( |
|
(c: Pick<Comment, 'author' | 'content' | 'dateCreated'>) => |
|
new Comment(c.author, c.content, new Date(c.dateCreated)) |
|
) |
|
.sort(Comment.sortChronologically), |
|
item.choices.map((c: Pick<Choice, 'label' | 'imageUrl' | 'participants' | 'counts'>) => { |
|
const choice = new Choice(c.label, c.imageUrl, new Map(c.participants)); |
|
choice.participants.forEach((value, key) => { |
|
choice.participants.set(key, new Set(value)); |
|
}); |
|
choice.updateCounts(); |
|
return choice; |
|
}) |
|
); |
|
} |
|
}
|
|
|