mobilizon.chapril.org-mobil.../js/src/types/event.model.ts

222 lines
5.0 KiB
TypeScript
Raw Normal View History

import { Address } from "@/types/address.model";
import type { IAddress } from "@/types/address.model";
import type { ITag } from "@/types/tag.model";
import type { IMedia } from "@/types/media.model";
import type { IComment } from "@/types/comment.model";
import type { Paginate } from "@/types/paginate";
import { Actor, Group } from "./actor";
import type { IActor, IGroup, IPerson } from "./actor";
import type { IParticipant } from "./participant.model";
import { EventOptions } from "./event-options.model";
import type { IEventOptions } from "./event-options.model";
import { EventJoinOptions, EventStatus, EventVisibility } from "./enums";
export interface IEventCardOptions {
hideDate: boolean;
loggedPerson: IPerson | boolean;
hideDetails: boolean;
organizerActor: IActor | null;
memberofGroup: boolean;
}
export interface IEventParticipantStats {
notApproved: number;
notConfirmed: number;
rejected: number;
participant: number;
creator: number;
moderator: number;
administrator: number;
going: number;
}
interface IEventEditJSON {
id?: string;
title: string;
description: string;
beginsOn: string;
endsOn: string | null;
status: EventStatus;
visibility: EventVisibility;
joinOptions: EventJoinOptions;
draft: boolean;
picture?: IMedia | { mediaId: string } | null;
attributedToId: string | null;
onlineAddress?: string;
phoneAddress?: string;
physicalAddress?: IAddress;
tags: string[];
options: IEventOptions;
contacts: { id?: string }[];
}
export interface IEvent {
id?: string;
2019-02-22 11:24:41 +01:00
uuid: string;
url: string;
local: boolean;
title: string;
slug: string;
2019-02-22 11:24:41 +01:00
description: string;
beginsOn: Date;
2019-09-02 14:35:50 +02:00
endsOn: Date | null;
publishAt: Date;
2019-02-22 11:24:41 +01:00
status: EventStatus;
visibility: EventVisibility;
joinOptions: EventJoinOptions;
draft: boolean;
2019-02-22 11:24:41 +01:00
picture: IMedia | null;
2019-02-22 11:24:41 +01:00
organizerActor?: IActor;
attributedTo?: IGroup;
participantStats: IEventParticipantStats;
participants: Paginate<IParticipant>;
2019-02-22 11:24:41 +01:00
relatedEvents: IEvent[];
comments: IComment[];
onlineAddress?: string;
phoneAddress?: string;
physicalAddress?: IAddress;
tags: ITag[];
options: IEventOptions;
contacts: IActor[];
toEditJSON(): IEventEditJSON;
}
export class EventModel implements IEvent {
id?: string;
2019-09-02 14:35:50 +02:00
beginsOn = new Date();
2019-09-02 14:35:50 +02:00
endsOn: Date | null = new Date();
title = "";
url = "";
uuid = "";
slug = "";
description = "";
2019-09-02 14:35:50 +02:00
local = true;
onlineAddress: string | undefined = "";
phoneAddress: string | undefined = "";
2019-09-02 14:35:50 +02:00
physicalAddress?: IAddress;
picture: IMedia | null = null;
2019-09-02 14:35:50 +02:00
visibility = EventVisibility.PUBLIC;
2019-09-02 14:35:50 +02:00
joinOptions = EventJoinOptions.FREE;
2019-09-02 14:35:50 +02:00
status = EventStatus.CONFIRMED;
draft = true;
2019-09-02 14:35:50 +02:00
publishAt = new Date();
participantStats = {
notApproved: 0,
notConfirmed: 0,
rejected: 0,
participant: 0,
moderator: 0,
administrator: 0,
creator: 0,
going: 0,
};
participants!: Paginate<IParticipant>;
2019-09-02 14:35:50 +02:00
relatedEvents: IEvent[] = [];
comments: IComment[] = [];
2019-09-02 14:35:50 +02:00
attributedTo?: IGroup = new Group();
organizerActor?: IActor = new Actor();
2019-09-02 14:35:50 +02:00
tags: ITag[] = [];
contacts: IActor[] = [];
options: IEventOptions = new EventOptions();
2019-09-02 14:35:50 +02:00
constructor(hash?: IEvent) {
if (!hash) return;
this.id = hash.id;
this.uuid = hash.uuid;
this.url = hash.url;
this.local = hash.local;
this.title = hash.title;
this.slug = hash.slug;
this.description = hash.description || "";
2019-09-02 14:35:50 +02:00
this.beginsOn = new Date(hash.beginsOn);
if (hash.endsOn) this.endsOn = new Date(hash.endsOn);
this.publishAt = new Date(hash.publishAt);
this.status = hash.status;
this.visibility = hash.visibility;
this.joinOptions = hash.joinOptions;
this.draft = hash.draft;
2019-09-02 14:35:50 +02:00
this.picture = hash.picture;
this.organizerActor = new Actor(hash.organizerActor);
this.attributedTo = new Group(hash.attributedTo);
2019-09-02 14:35:50 +02:00
this.participants = hash.participants;
this.relatedEvents = hash.relatedEvents;
this.onlineAddress = hash.onlineAddress;
this.phoneAddress = hash.phoneAddress;
this.physicalAddress = hash.physicalAddress
? new Address(hash.physicalAddress)
: undefined;
this.participantStats = hash.participantStats;
2019-09-02 14:35:50 +02:00
this.contacts = hash.contacts;
2019-09-02 14:35:50 +02:00
this.tags = hash.tags;
2019-09-09 11:21:42 +02:00
if (hash.options) this.options = hash.options;
}
toEditJSON(): IEventEditJSON {
2019-09-09 11:21:42 +02:00
return {
id: this.id,
title: this.title,
description: this.description,
beginsOn: this.beginsOn.toISOString(),
endsOn: this.endsOn ? this.endsOn.toISOString() : null,
status: this.status,
visibility: this.visibility,
joinOptions: this.joinOptions,
draft: this.draft,
tags: this.tags.map((t) => t.title),
2019-09-09 11:21:42 +02:00
onlineAddress: this.onlineAddress,
phoneAddress: this.phoneAddress,
physicalAddress: this.physicalAddress,
options: this.options,
attributedToId:
this.attributedTo && this.attributedTo.id ? this.attributedTo.id : null,
contacts: this.contacts.map(({ id }) => ({
id,
})),
2019-09-09 11:21:42 +02:00
};
2019-09-02 14:35:50 +02:00
}
}