Files
nirvana/models/link.ts
T

88 lines
2.0 KiB
TypeScript

import { Timestamp } from "firebase/firestore";
export default class Link {
id: string;
name: string;
description: string;
link: string; //url for file
state: LinkState = LinkState.active;
type: LinkType;
teamId: string;
// if it's not a teamAttachment, then have a list of members who it's for
private _recipients: string[]; // userIds
createdByUserId: string;
createdDate: Timestamp;
constructor(
_name: string,
_description: string,
_link: string,
_teamId: string,
recipientsArr: string[],
_createdByUserId: string
) {
this.name = _name;
this.description = _description;
this.link = _link;
this.teamId = _teamId;
this.recipients = recipientsArr;
this.createdByUserId = _createdByUserId;
this.type = Link.getLinkType(_link);
}
public get recipients(): string[] {
return this._recipients;
}
public set recipients(arrUserIds: string[]) {
if (!this._recipients || this._recipients?.length == 0) {
this._recipients = null;
} else {
this._recipients = arrUserIds;
}
}
static getLinkType(url: string): LinkType {
if (url.includes(LinkType.github)) {
return LinkType.github;
} else if (url.includes(LinkType.atlassian)) {
return LinkType.atlassian;
} else if (url.includes(LinkType.googleDrive)) {
return LinkType.googleDrive;
} else if (
url.includes(".png") ||
url.includes(".jpg") ||
url.includes(".svg") ||
url.includes(".gif")
) {
return LinkType.image;
} else if (url.includes(LinkType.pdf)) {
return LinkType.pdf;
} else if (url.includes(LinkType.codePile)) {
return LinkType.codePile;
} else {
return LinkType.default;
}
}
}
export enum LinkState {
active = "active",
archived = "archived",
}
export enum LinkType {
default = "default",
github = "github",
atlassian = "atlassian",
googleDrive = "drive.google",
onedrive = "onedrive",
image = "image",
pdf = "pdf",
codePile = "codepile",
}