Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daffa/Define contracts #18

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions contracts/commons/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import {z} from 'zod';
* @property {string} message - A message providing additional information about the response.
* @property {string | object | Array<unknown> | null} data - The data returned in the response. This can be a string, an object, an array, or null.
*
* @example
* // Example usage:
* const response: ResponseMeta = {
* status: 200,
* message: 'Success',
* data: {
* id: 1,
* name: 'Sample Data'
* }
* };
*
* @remarks
* The `data` property is flexible and can accommodate different types of response data.
*
Expand Down
27 changes: 27 additions & 0 deletions contracts/commons/Timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Timestamp} from 'firebase/firestore';
import {z} from 'zod';

/**
* @interface Timeline
* @description Represents the timeline of an event or activity.
*
* @property {Timestamp} started_at - The timestamp when the event/activity started.
* @property {Timestamp} ended_at - The timestamp when the event/activity ended.
*
*
* @since 1.0.0
*
*/
export interface Timeline {
started_at: Timestamp;
ended_at?: Timestamp;
}

export const TimelineSchema: z.ZodSchema<Timeline> = z.object({
started_at: z.instanceof(Timestamp, {
message: 'Started At must be an instance of Firebase Firestore Timestamp',
}),
ended_at: z.instanceof(Timestamp, {
message: 'Ended At must be an instance of Firebase Firestore Timestamp',
}).optional(),
});
28 changes: 28 additions & 0 deletions contracts/enums/FirestoreCollectionEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* FirestoreCollectionEnum
* @description Firestore collection names
* @since 1.0.0
* @enum
* @readonly
* @type {object}
* @property {string} PARTNERSHIPS - The partnerships collection
* @property {string} RESEARCHES - The researches collection
* @property {string} USERS - The users collection
* @property {string} SKILLS - The skills collection
* @remarks
* This enum can be used to reference Firestore collection names in the application.
* @example
* // This example demonstrates how to use the FirestoreCollectionEnum in the application
* import {FirestoreCollectionEnum} from 'contracts/enums/FirestoreCollectionEnum';
* const collectionName = FirestoreCollectionEnum.USERS;
* console.log(collectionName); // Output: 'users'
*/

export const FirestoreCollectionEnum = {
PARTNERSHIPS: 'partnerships',
RESEARCHES: 'researches',
USERS: 'users',
SKILLS: 'skills',
} as const;

export type FirestoreCollectionEnum = typeof FirestoreCollectionEnum[keyof typeof FirestoreCollectionEnum];
43 changes: 43 additions & 0 deletions contracts/enums/LaboratoryRoleEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Enum for LaboratoryRoleEnum
* @readonly
* @enum {string}
* @description Represents the roles of a user in the laboratory.
* @property {string} PROFESSOR - The professor role
* @property {string} GUEST_PROFESSOR - The guest professor role
* @property {string} LABORATORY_ASSISTANT - The laboratory assistant role
* @property {string} RESEARCH_STUDENT - The research student role
* @property {string} STUDENT - The student role
* @property {string} NO_TYPE - The intern role
* @since 1.0.0
*
* @example
* // Example usage:
* const laboratoryRole: LABORATORY_ROLE = LABORATORY_ROLE.PROFESSOR;
* console.log(laboratoryRole); // Output: '40001'
*/

export const LABORATORY_ROLE = {
PROFESSOR: '40001',
GUEST_PROFESSOR: '40002',
LABORATORY_ASSISTANT: '40003',
RESEARCH_STUDENT: '40004',
STUDENT: '40005',
INTERN: '40006',
NO_TYPE: '49999',
} as const;

/**
* @type {string[]} LABORATORY_ROLE_VALUE
* @description The value of the laboratory role can include multiple roles.
* @since 1.0.0
*/
export const VALID_MULTIPLE_ROLES: string[] = [
LABORATORY_ROLE.LABORATORY_ASSISTANT,
LABORATORY_ROLE.RESEARCH_STUDENT,
LABORATORY_ROLE.STUDENT,
];

export type VALID_MULTIPLE_ROLES_VALUE = typeof VALID_MULTIPLE_ROLES[number];

export type LABORATORY_ROLE_VALUE = typeof LABORATORY_ROLE[keyof typeof LABORATORY_ROLE];
25 changes: 25 additions & 0 deletions contracts/enums/PartnershipEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Partnership Type Enum
* @enum
* @property {string} ACADEMIC - The academic partnership type
* @property {string} INDUSTRY - The industry partnership type
* @property {string} GOVERNMENT - The government partnership type
* @property {string} MEDIA - The media partnership type
* @property {string} NON_PROFIT - The non-profit partnership type
* @readonly
* @since 1.0.0
* @example
* // Example usage:
* const partnershipType: PARTNERSHIP_TYPE = PARTNERSHIP_TYPE.ACADEMIC;
* console.log(partnershipType); // Output: '30001'
*/

export const PARTNERSHIP_TYPE = {
ACADEMIC: '30001',
INDUSTRY: '30002',
GOVERNMENT: '30003',
MEDIA: '30004',
NON_PROFIT: '30005',
} as const;

export type PARTNERSHIP_TYPE_VALUE = typeof PARTNERSHIP_TYPE[keyof typeof PARTNERSHIP_TYPE];
21 changes: 21 additions & 0 deletions contracts/enums/ResearchEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* ResearchType enum
* @readonly
* @enum {string}
* @description Represents the types of research.
* @since 1.0.0
* @example
* // Example usage:
* const researchType: RESEARCH_TYPE = RESEARCH_TYPE.CONFERENCE;
* console.log(researchType); // Output: '10001'
*
*/

export const RESEARCH_TYPE = {
CONFERENCE: '20001',
JOURNAL: '20002',
WORKSHOP: '20003',
OTHER: '20004',
} as const;

export type RESEARCH_TYPE_VALUE = typeof RESEARCH_TYPE[keyof typeof RESEARCH_TYPE];
26 changes: 26 additions & 0 deletions contracts/enums/UserRoleEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* User Role Enum
* @readonly
* @enum {string}
* @description Represents the roles of a user in the system.
* @property {string} SUPER_ADMIN - The super admin role
* @property {string} ADMIN - The admin role
* @property {string} MEMBER - The member role
* @property {string} GUEST - The guest role
* @property {string} NO_TYPE - The default role
* @since 1.0.0
* @example
* // Example usage:
* const userRole: USER_ROLE = USER_ROLE.ADMIN;
* console.log(userRole); // Output: '10002'
*/

export const USER_ROLE = {
SUPER_ADMIN: '10001',
ADMIN: '10002',
MEMBER: '10003',
GUEST: '10004',
NO_TYPE: '19999',
} as const;

export type USER_ROLE_VALUE = typeof USER_ROLE[keyof typeof USER_ROLE];
39 changes: 39 additions & 0 deletions contracts/files/FileInformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {Timestamp} from 'firebase/firestore';
import {z} from 'zod';

/**
* @interface FileInformation
* @description Represents the information of a file.
*
* @property {string} name - The name of the file.
* @property {string} extension - The extension of the file.
* @property {number} size - The size of the file in bytes.
* @property {Timestamp} uploaded_at - The timestamp when the file was uploaded.
*
* @since 1.0.0
*/

export interface FileInformation {
name: string;
extension: string;
size: number;
uploaded_at: Timestamp;
}

export const FileInformationSchema: z.ZodSchema<FileInformation> = z.object({
name: z.string({
required_error: 'File name is required',
invalid_type_error: 'File name must be a string',
}),
extension: z.string({
required_error: 'File extension is required',
fadliz marked this conversation as resolved.
Show resolved Hide resolved
invalid_type_error: 'File extension must be a string',
}),
size: z.number({
required_error: 'File size is required',
invalid_type_error: 'File size must be a number',
}),
uploaded_at: z.instanceof(Timestamp, {
message: 'Upload At must be an instance of Timestamp',
}),
});
28 changes: 28 additions & 0 deletions contracts/partnerships/PartnershipMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {z} from 'zod';

import {Timeline, TimelineSchema} from '../commons/Timeline';

/**
* PartnershipMetadata is an interface that defines the structure of the PartnershipMetadata data
* @interface
* @property {boolean} show_on_homepage - A boolean value indicating whether the partnership should be shown on the homepage.
* @property {Timeline} timeline - The timeline of the partnership.
*
* @remarks
* The show_on_homepage property can be used to control the visibility of the partnership on the homepage.
* The timeline property can be used to define the timeline of the partnership.
*
* @since 1.0.0
*/
export interface PartnershipMetadata {
show_on_homepage: boolean;
timeline: Timeline;
}

export const PartnershipMetadataSchema = z.object({
show_on_homepage: z.boolean({
required_error: 'Show on homepage is required',
invalid_type_error: 'Show on homepage must be a boolean',
}),
timeline: TimelineSchema,
});
57 changes: 57 additions & 0 deletions contracts/partnerships/PartnershipProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {Timestamp} from 'firebase/firestore';
import {z} from 'zod';

import {FileInformation, FileInformationSchema} from '../files/FileInformation';
import {PartnershipMetadata, PartnershipMetadataSchema} from './PartnershipMetadata';

/**
* @interface PartnershipProfile
* @description Represents the profile information of a partnership, including basic information and timestamps.
*
* @property {string} organization_name - The name of the organization.
* @property {string} description - The description of the partnership.
* @property {FileInformation} logo - The logo of the organization.
* @property {string} website - The website of the organization.
* @property {Timestamp} created_at - The timestamp when the profile was created.
* @property {Timestamp} updated_at - The timestamp when the profile was last updated.
* @property {PartnershipMetadata} metadata - The metadata of the partnership.
*
* @remarks
* The timestamps can be useful for tracking the creation and modification dates of the partnership profile.
*
* @since 1.0.0
*/

export interface PartnershipProfile {
description: string;
logo: FileInformation;
metadata: PartnershipMetadata
organization_name: string;
website?: string;
created_at: Timestamp;
updated_at: Timestamp;
}

export const PartnershipProfileSchema: z.ZodSchema<PartnershipProfile> = z.object({
organization_name: z.string({
required_error: 'Name is required',
invalid_type_error: 'Name must be a string',
}),
description: z.string({
required_error: 'Description is required',
invalid_type_error: 'Description must be a string',
}),
logo: FileInformationSchema,
website: z.string({
invalid_type_error: 'Website must be a string',
}).url({
message: 'Input should be a valid URI',
}).optional(),
created_at: z.instanceof(Timestamp, {
message: 'Created At must be an instance of Firebase Firestore Timestamp',
}),
updated_at: z.instanceof(Timestamp, {
message: 'Updated At must be an instance of Firebase Firestore Timestamp',
}),
metadata: PartnershipMetadataSchema,
});
63 changes: 63 additions & 0 deletions contracts/researches/ResearchArticle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {Timestamp} from 'firebase/firestore';
import {z} from 'zod';

import {RESEARCH_TYPE, RESEARCH_TYPE_VALUE} from '../enums/ResearchEnum';
import {ResearchMetadata, ResearchMetadataSchema} from './ResearchMetadata';

/**
* ResearchArticle is an interface that defines the structure of the ResearchArticle data
* @interface
* @property {string[]} authors - The authors of the article
* @property {string} cited - The cited of the article
* @property {string} research_id - The research id of the article
* @property {string} title - The title of the article
* @property {string} year - The year of the article
* @property {RESEARCH_TYPE_VALUE} research_type - The research type of the article
* @property {Timestamp} created_at - The timestamp when the article was created.
* @property {Timestamp} updated_at - The timestamp when the article was last updated.
*
* @since 1.0.0
*/
export interface ResearchArticle {
authors?: string[];
cited: string;
research_id: string;
research_type: RESEARCH_TYPE_VALUE
title: string;
year: string;
metadata: ResearchMetadata;
created_at?: Timestamp;
updated_at?: Timestamp;
}

export const ResearchArticleSchema: z.ZodSchema<ResearchArticle> = z.object({
title: z.string({
required_error: 'Title is required',
invalid_type_error: 'Title must be a string',
}),
authors: z.array(z.string(), {
invalid_type_error: 'Authors must be an array of string',
}).optional(),
year: z.string({
required_error: 'Year is required',
invalid_type_error: 'Year must be a string',
}),
cited: z.string({
required_error: 'Cited is required',
invalid_type_error: 'Cited must be a string',
}),
research_id: z.string({
required_error: 'Research ID is required',
invalid_type_error: 'Research ID must be a string',
}),
metadata: ResearchMetadataSchema,
research_type: z.nativeEnum(RESEARCH_TYPE, {
message: 'Research Type must be in the enum list',
}),
created_at: z.instanceof(Timestamp, {
message: 'Created At must be an instance of Firebase Firestore Timestamp',
}),
updated_at: z.instanceof(Timestamp, {
message: 'Updated At must be an instance of Firebase Firestore Timestamp',
}),
});
Loading
Loading