diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7844568 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "types"] + path = types + url = https://github.com/Quento-Solutions/Quento-Types.git diff --git a/Dockerfile b/Dockerfile index c3f10c8..7d39cce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ EXPOSE 80 WORKDIR /usr/src/ RUN mkdir /usr/src/content COPY package*.json ./ - +RUN git pull --recurse-submodules RUN npm install COPY . . diff --git a/types b/types new file mode 160000 index 0000000..709d635 --- /dev/null +++ b/types @@ -0,0 +1 @@ +Subproject commit 709d63537b760069318cd399f928e262d3c72769 diff --git a/types/firebaseTypes.ts b/types/firebaseTypes.ts deleted file mode 100644 index 7251f8c..0000000 --- a/types/firebaseTypes.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface Date_t_F -{ - seconds : number; - nanoseconds : number -} -export interface Date_t_A -{ - _seconds : number; - _nanoseconds : number -} -export interface StoredImage -{ - fileName : string; - imageURL : string; -} -export const firebaseDate = (date : Date_t_F) => date ? new Date(date.seconds * 1000) : new Date(0); -export const algoliaDate = (date : Date_t_A) => new Date(date._seconds * 1000); diff --git a/types/index.ts b/types/index.ts deleted file mode 100644 index f75c842..0000000 --- a/types/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * as Notes from './notes'; -export * as Subjects from './subjects'; -export * as Suggestions from './suggestions' -export * as User from './user'; -export * as School from './schools'; -export * as Questions from './questions'; -export * as Responses from './responses'; - -export * as FirebaseTypes from './firebaseTypes'; \ No newline at end of file diff --git a/types/newsletters.ts b/types/newsletters.ts deleted file mode 100644 index 6a848b8..0000000 --- a/types/newsletters.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Module } from 'vuex-module-decorators'; - - -import {Subject_O , Grade_O} from './subjects' - -export interface Newsletter_t -{ - title : string; - contents : string; - - createdAt : Date; - views : number; - - backgroundImageUrl : string; - authorPhotoUrl : string; - authorDisplayName : string; - - id ?: string; -} -export interface Date_t_F -{ - seconds : number; - nanoseconds : number - -} -export interface Newsletter_t_F -{ - - title : string; - contents : string; - - backgroundImageUrl : string; - authorPhotoUrl : string; - authorDisplayName : string; - - createdAt : Date | Date_t_F; - views : number; -} - -export class Newsletter -{ - - constructor( - opts : Newsletter_t - ){ - return Object.assign(this, opts) - } - - static fromFirebase = (doc : Newsletter_t_F, id ?: string) => - { - const createdAt = new Date((doc.createdAt as Date_t_F).seconds * 1000) - const obj = {...doc, createdAt, id}; - return new Newsletter(obj) - } - - static toFirebase(doc: Newsletter) : Newsletter_t_F - { - const {id, ...firebaseDoc} = {...doc} - return firebaseDoc - } -} - -export interface Newsletter extends Newsletter_t {} diff --git a/types/notes.ts b/types/notes.ts deleted file mode 100644 index 034362d..0000000 --- a/types/notes.ts +++ /dev/null @@ -1,67 +0,0 @@ - -import {Subject_O , Grade_O} from './subjects' -import {Date_t_F, firebaseDate, StoredImage} from './firebaseTypes'; - - -export interface Note_t -{ - title : string; - uid : string; - userDisplayName : string; - userPhotoUrl ?: string; - - images ?: string[]; - contents ?: string; - storedImages ?: StoredImage[]; - - createdAt : Date; - upVotes : number; - views : number; - - subject : Subject_O; - grade : Grade_O; - id ?: string; -} -export interface Note_t_F -// How the data is stored in firebase -{ - title : string; - uid : string; - userDisplayName : string; - userPhotoUrl ?: string; - - images ?: string[]; - contents ?: string; - storedImages ?: StoredImage[]; - - createdAt : Date_t_F | Date; - upVotes : number; - subject : Subject_O; - grade : Grade_O; - views : number; -} - -export class Note -{ - - constructor( - opts : Note_t - ){ - return Object.assign(this, opts) - } - - static fromFirebase = (doc : Note_t_F, id ?: string) => - { - - const createdAt = firebaseDate(doc.createdAt as Date_t_F) - const obj = {...doc, createdAt, id}; - return new Note(obj) - } - - static toFirebase = (note : Note) : Note_t_F => - { - const {id, ...firebaseDoc} = {...note} - return firebaseDoc - } -} -export interface Note extends Note_t {} diff --git a/types/notifications.ts b/types/notifications.ts deleted file mode 100644 index 006fcaa..0000000 --- a/types/notifications.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Date_t_F, firebaseDate } from './firebaseTypes' -import { Newsletter_t_F } from './newsletters' -import { Note_t_F } from './notes' -import { Question_t_F } from './questions' -import { Response_t_F } from './responses' - -export const NotificationDataList = ['QUESTION', "NEWSLETTER", "NOTE", "RESPONSE"] as const -export const NotificationActionList = ['POST', "RESPONSE", "POPULAR"] as const - -export type NotificationAction_O = typeof NotificationActionList[number] -export type NotificationData_O = typeof NotificationDataList[number] - -export interface Notification_t_F { - createdAt: Date_t_F | Date - docId: string - read: boolean - docData: NotificationDataMap[Type] - dataType: Type - userId?: string - avatarDisplayName ?: string; - avatarPhotoUrl ?: string; - redirectUrl : string; - title ?: string; -} - -export type NotificationMapType = { - [index in NotificationData_O]: any -} -export interface NotificationDataMap extends NotificationMapType { - QUESTION: Question_t_F; - NEWSLETTER : Newsletter_t_F; - RESPONSE : Response_t_F; - NOTE : Note_t_F; -} - -export interface Notification_t { - id?: string - createdAt: Date - docId: string - read: boolean - docData: NotificationDataMap[DataType] - dataType: DataType - userId?: string - avatarPhotoUrl ?: string; - avatarDisplayName ?: string; - redirectUrl : string; - title ?: string; -} - -export class Notification { - constructor(opts: Notification_t) { - return Object.assign(this, opts) - } - - static fromFirebase = ( - doc: Notification_t_F, - id?: string - ) => { - const obj = { - ...doc, - createdAt: firebaseDate(doc.createdAt as Date_t_F), - id - } - return new Notification(obj) - } - - static toFirebase( - question: Notification - ): Notification_t_F { - const { id, ...firebaseDoc } = { ...question } - return firebaseDoc - } -} -export interface Notification - extends Notification_t {} diff --git a/types/questions.ts b/types/questions.ts deleted file mode 100644 index b246b69..0000000 --- a/types/questions.ts +++ /dev/null @@ -1,80 +0,0 @@ -import {Date_t_F, Date_t_A, firebaseDate, algoliaDate, StoredImage} from './firebaseTypes'; -import type {Keyword_O} from './subjects' -import type {Subject_O , Grade_O,} from './subjects' - -export interface Question_t -{ - id ?: string; - createdAt : Date; - - title : string; - contents : string; - keywords ?: Keyword_O[]; - subject : Subject_O; - grade : Grade_O; - storedImages ?: StoredImage[]; - - - upVotes : number; - views : number; - responses : number; - - userPhotoUrl ?: string; - userId : string; - userDisplayName : string; -} - - -export interface Question_t_F -{ - createdAt : Date_t_F | Date; - - title : string; - contents : string; - subject : Subject_O; - grade : Grade_O; - - upVotes : number; - views : number; - responses : number; - keywords ?: Keyword_O[] - storedImages ?: StoredImage[]; - - userPhotoUrl ?: string; - userId : string; - userDisplayName : string; -} -export type Question_t_A = Question_t_F & -{ - createdAt : Date_t_A - objectID : string; -} - -export class Question -{ - - constructor( - opts : Question_t - ){ - return Object.assign(this, opts) - } - - static fromFirebase = (doc : Question_t_F, id ?: string) => - { - - const obj = {...doc, createdAt : firebaseDate(doc.createdAt as Date_t_F), id}; - return new Question(obj) - } - static fromAlgolia = (doc : Question_t_A) => - { - const {objectID, ...obj} = {...doc, createdAt : algoliaDate(doc.createdAt as Date_t_A), id : doc.objectID}; - return new Question(obj) - } - - static toFirebase(question : Question) : Question_t_F - { - const {id, ...firebaseDoc} = {...question} - return firebaseDoc - } -} -export interface Question extends Question_t {} diff --git a/types/responses.ts b/types/responses.ts deleted file mode 100644 index 8a3feb2..0000000 --- a/types/responses.ts +++ /dev/null @@ -1,64 +0,0 @@ -import {Date_t_F, firebaseDate} from './firebaseTypes'; -import type {Keyword_O} from './subjects' -import type {Subject_O , Grade_O} from './subjects' - -export interface Response_t -{ - id ?: string; - createdAt : Date; - userId : string; - questionId : string; - - contents : string; - - upVotes : number; - views : number; - - userPhotoUrl ?: string; - userDisplayName : string; -} - - -export interface Response_t_F -{ - createdAt : Date_t_F | Date; - - contents : string; - - upVotes : number; - views : number; - questionId : string; - - userPhotoUrl ?: string; - userId : string; - userDisplayName : string; -} - -export type Response_t_A = Response_t_F & -{ - objectID : string; -} - -export class Response -{ - - constructor( - opts : Response_t - ){ - return Object.assign(this, opts) - } - - static fromFirebase = (doc : Response_t_F, id ?: string) => - { - - const obj = {...doc, createdAt : firebaseDate(doc.createdAt as Date_t_F), id}; - return new Response(obj) - } - - static toFirebase(doc : Response) : Response_t_F - { - const {id, ...firebaseDoc} = {...doc} - return firebaseDoc - } -} -export interface Response extends Response_t {} diff --git a/types/schools.ts b/types/schools.ts deleted file mode 100644 index ada07a6..0000000 --- a/types/schools.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const SchoolList = [ - 'Colonel By Secondary School', - 'Lisgar Collegiate Institute', - 'Earl of March Secondary School', - 'Bell High School', - 'Longfields-Davidson Heights Secondary School', - 'Merivale High School', - 'John McCrae Secondary School', - "École Secondaire Catholique Pierre-Savard", - 'Other' -] as const - -export type School_O = typeof SchoolList[number] diff --git a/types/subjects.ts b/types/subjects.ts deleted file mode 100644 index c260aca..0000000 --- a/types/subjects.ts +++ /dev/null @@ -1,129 +0,0 @@ -export const SubjectGroups = { - Sciences: ['Physics', 'Chemistry', 'Biology', 'Math'], - Languages: ['English', 'French', 'Spanish'], - Arts: ['Visual Arts', 'Music', 'Dance', 'Drama', 'Film'], - 'Social Sciences': ['TOK', 'Geography', 'History', 'Business'], - Technology: ['ICS', 'ITGS', 'ComTech'], - Other : ["Phys Ed", "General"] -} as const - -export const AllSubjectList = [ - 'Physics', - 'Chemistry', - 'Biology', - 'Math', - 'English', - 'French', - 'Spanish', - 'Visual Arts', - 'Music', - 'Dance', - 'Drama', - 'Film', - 'TOK', - 'Geography', - 'History', - 'Business', - 'ICS', - 'ITGS', - 'ComTech' -] - -export const SortOptionsList = [ - { - name: 'Up Votes', - value: 'upVotes' - }, - { - name: 'Views', - value: 'views' - }, - { - name: 'Recent', - value: 'createdAt' - } -] as const - -export type SortOptions_O = typeof SortOptionsList[number]['value'] -export type SubjectGroup_O = keyof typeof SubjectGroups - -export const GradeList = [7, 8, 9, 10, 11, 12, 'ALL'] as const -export type Grade_O = typeof GradeList[number] - -export const SubjectList = Object.entries(SubjectGroups).flatMap( - (group) => group[1] -) - -export const SubjectGroupList: SubjectGroup_O[] = Object.keys( - SubjectGroups -) as SubjectGroup_O[] - -export const SubjectOptions: { - [index in Subject_O]?: boolean -} = SubjectList.reduce((o, key) => ({ ...o, [key]: false }), {}) - -export type Subject_O = typeof SubjectList[number] - -export const SubjectIconList: { - [index in Subject_O | SubjectGroup_O]: string -} = { - Sciences: 'bx-bulb', - Languages: 'bx-pen', - Arts: 'bx-palette', - 'Social Sciences': 'bx-world', - Technology: 'bx-server', - Other: "bx-list-plus", - - Math: 'bx-brain', - Physics: 'bx-atom', - Chemistry: 'bxs-flask', - Biology: 'bx-dna', - English: 'bx-book-bookmark', - French: 'bx-book', - Spanish: 'bx-bible', - 'Visual Arts': 'bxs-brush', - Music: 'bxs-music', - Dance: 'bxs-guitar-amp', - Drama: 'bx-mask', - Film: 'bx-camera-movie', - TOK: 'bx-network-chart', - Geography: 'bx-globe', - History: 'bxs-landmark', - Business: 'bx-briefcase', - ICS: 'bx-code-alt', - ITGS: 'bx-data', - ComTech: 'bxs-component', - "Phys Ed" : "bxs-basketball", - General : "bx-slider-alt" -} as const - -export interface SubjectItem { - name: Subject_O - iconClass: typeof SubjectIconList[SubjectItem['name']] -} - -export interface SubjectGroup { - name: SubjectGroup_O - iconClass: string - items: SubjectItem[] -} - -export const NestedSubjectList: SubjectGroup[] = Object.entries( - SubjectGroups -).map((kv, index) => { - const key = kv[0] as SubjectGroup_O - const subjects = SubjectGroups[key] as readonly Subject_O[] - return { - name: key, - iconClass: SubjectIconList[key], - items: [ - ...subjects.map((name) => ({ - name, - iconClass: SubjectIconList[name] - })) - ] - } -}) - -export type Keyword_O = Subject_O | SubjectGroup_O | Grade_O -export const KeywordList = [...SubjectList, ...GradeList, ...SubjectGroupList] diff --git a/types/suggestions.ts b/types/suggestions.ts deleted file mode 100644 index dd090f2..0000000 --- a/types/suggestions.ts +++ /dev/null @@ -1,44 +0,0 @@ -export interface Suggestion_t -{ - id ?: string; - contents : string; - createdAt : Date; - title : string; - uid : string; - upVotes : number; - userDisplayName : string; -} - -export interface Suggestion_t_F -{ - contents : string; - createdAt : Date; - title : string; - uid : string; - upVotes : number; - userDisplayName : string; -} - -export class Suggestion -{ - - constructor( - opts : Suggestion_t - ){ - return Object.assign(this, opts) - } - - static fromFirebase = (doc : Suggestion_t_F, id ?: string) => - { - - const obj = {...doc, createdAt : new Date(doc.createdAt), id}; - return new Suggestion(obj) - } - - toFirebase() : Suggestion_t_F - { - const {id, ...firebaseDoc} = {...this} - return firebaseDoc - } -} -export interface Suggestion extends Suggestion_t {} diff --git a/types/user.ts b/types/user.ts deleted file mode 100644 index 3e34060..0000000 --- a/types/user.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Grade_O, Subject_O } from './subjects' - -import { School_O } from './schools' - -export type User = { - uid: string - displayName?: string | null - email?: string | null - phoneNumber?: string | null - photoURL?: string | null - providerId?: string - emailVerified: boolean - isAnonymous?: boolean - isAdmin?: boolean -} | null - -export interface UserData { - email: string - - likedSuggestions?: string[] - likedNotes?: string[] - likedQuestions?: string[] - likedResponses?: string[] - - userGuideClosed?: boolean - userInformationAdded?: boolean - - displayName?: string | null - photoURL?: string | null - currentGrade?: Grade_O - interestedSubjects?: Subject_O[] - bio?: string - school?: School_O - - postedSuggestions?: string[] - postedNotes?: string[] - - newsletter?: boolean - progressionExp?: number - progressionLevel?: number - totalExp : number; - - discordId?: string - discordUsername?: string - photoFileName?: string | null - - notifications?: boolean -}