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/rnd #11

Merged
merged 4 commits into from
Jul 11, 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
43 changes: 43 additions & 0 deletions contracts/commons/Response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {z} from 'zod';

/**
* @interface ResponseMeta
* @description Represents the metadata of a response, including status, message, and data.
*
* @property {number} status - The status code of the response.
* @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.
*
* @since 1.0.0
*/
export interface ResponseMeta {
status: number;
message: string;
data: string | object | Array<unknown> | null;
}

export const ResponseMetaSchema: z.ZodSchema<ResponseMeta> = z.object({
status: z.number({
required_error: 'Status is required',
invalid_type_error: 'Status must be a number',
}),
message: z.string({
required_error: 'Message is required',
invalid_type_error: 'Message must be a string',
}),
data: z.union([z.string(), z.object({}), z.array(z.unknown()), z.null()]),
});
45 changes: 41 additions & 4 deletions contracts/users/UserBasicInformation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import {z} from 'zod';

/**
* @interface UserBasicInformation
* @description Represents the basic information of a user.
*
* @property {string} first_name - The first name of the user.
* @property {string} last_name - The last name of the user.
* @property {string} email - The email address of the user.
* @property {string} student_id - The student ID of the user.
*
* @example
* // Example usage:
* const user: UserBasicInformation = {
* first_name: 'John',
* last_name: 'Doe',
* email: 'john.doe@example.com',
* student_id: '1302194004'
* };
*
* @remarks
* This interface can be extended to include more user-related information
* as needed for various applications.
*
* @since 1.0.0
*/

export interface UserBasicInformation {
first_name: string;
last_name: string;
Expand All @@ -8,14 +33,26 @@ export interface UserBasicInformation {
}

export const UserBasicInformationSchema: z.ZodSchema<UserBasicInformation> = z.object({
first_name: z.string(),
last_name: z.string(),
email: z.string()
first_name: z.string({
required_error: 'First name is required',
invalid_type_error: 'First name must be a string',
}),
last_name: z.string({
required_error: 'Last name is required',
invalid_type_error: 'Last name must be a string',
}),
email: z.string({
required_error: 'Email is required',
invalid_type_error: 'Email must be a string',
})
.email()
.refine((email) => /@(telkomuniversity\.ac\.id|student\.telkomuniversity\.ac\.id)$/.test(email), {
message: 'Email must be from telkomuniversity.ac.id or student.telkomuniversity.ac.id domains',
}),
student_id: z.string().refine((id) => id.length === 10 || id.length === 12, {
student_id: z.string({
required_error: 'Student ID is required',
invalid_type_error: 'Student ID must be a string',
}).refine((id) => id.length === 10 || id.length === 12, {
message: 'Student ID must be either 10 or 12 characters long',
}),
});
26 changes: 26 additions & 0 deletions contracts/users/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ import {z} from 'zod';

import {UserBasicInformation, UserBasicInformationSchema} from './UserBasicInformation';

/**
* @interface UserProfile
* @description Represents the profile information of a user, including basic information and timestamps.
*
* @property {UserBasicInformation} basic_information - The basic information of the user.
* @property {Timestamp} created_at - The timestamp when the profile was created.
* @property {Timestamp} updated_at - The timestamp when the profile was last updated.
*
* @example
* // Example usage:
* const userProfile: UserProfile = {
* basic_information: {
* first_name: 'Jane',
* last_name: 'Doe',
* email: 'jane.doe@example.com',
* student_id: '1302194004'
* },
* created_at: Timestamp.now(),
* updated_at: Timestamp.now()
* };
*
* @remarks
* The timestamps can be useful for tracking the creation and modification dates of the user profile.
*
* @since 1.0.0
*/
export interface UserProfile {
basic_information: UserBasicInformation;
created_at: Timestamp;
Expand Down
11 changes: 10 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions frontend/src/contracts/commons/Response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {z} from 'zod';

/**
* @interface ResponseMeta
* @description Represents the metadata of a response, including status, message, and data.
*
* @property {number} status - The status code of the response.
* @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.
*
* @since 1.0.0
*/
export interface ResponseMeta {
status: number;
message: string;
data: string | object | Array<unknown> | null;
}

export const ResponseMetaSchema: z.ZodSchema<ResponseMeta> = z.object({
status: z.number({
required_error: 'Status is required',
invalid_type_error: 'Status must be a number',
}),
message: z.string({
required_error: 'Message is required',
invalid_type_error: 'Message must be a string',
}),
data: z.union([z.string(), z.object({}), z.array(z.unknown()), z.null()]),
});
45 changes: 41 additions & 4 deletions frontend/src/contracts/users/UserBasicInformation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import {z} from 'zod';

/**
* @interface UserBasicInformation
* @description Represents the basic information of a user.
*
* @property {string} first_name - The first name of the user.
* @property {string} last_name - The last name of the user.
* @property {string} email - The email address of the user.
* @property {string} student_id - The student ID of the user.
*
* @example
* // Example usage:
* const user: UserBasicInformation = {
* first_name: 'John',
* last_name: 'Doe',
* email: 'john.doe@example.com',
* student_id: '1302194004'
* };
*
* @remarks
* This interface can be extended to include more user-related information
* as needed for various applications.
*
* @since 1.0.0
*/

export interface UserBasicInformation {
first_name: string;
last_name: string;
Expand All @@ -8,14 +33,26 @@ export interface UserBasicInformation {
}

export const UserBasicInformationSchema: z.ZodSchema<UserBasicInformation> = z.object({
first_name: z.string(),
last_name: z.string(),
email: z.string()
first_name: z.string({
required_error: 'First name is required',
invalid_type_error: 'First name must be a string',
}),
last_name: z.string({
required_error: 'Last name is required',
invalid_type_error: 'Last name must be a string',
}),
email: z.string({
required_error: 'Email is required',
invalid_type_error: 'Email must be a string',
})
.email()
.refine((email) => /@(telkomuniversity\.ac\.id|student\.telkomuniversity\.ac\.id)$/.test(email), {
message: 'Email must be from telkomuniversity.ac.id or student.telkomuniversity.ac.id domains',
}),
student_id: z.string().refine((id) => id.length === 10 || id.length === 12, {
student_id: z.string({
required_error: 'Student ID is required',
invalid_type_error: 'Student ID must be a string',
}).refine((id) => id.length === 10 || id.length === 12, {
message: 'Student ID must be either 10 or 12 characters long',
}),
});
26 changes: 26 additions & 0 deletions frontend/src/contracts/users/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ import {z} from 'zod';

import {UserBasicInformation, UserBasicInformationSchema} from './UserBasicInformation';

/**
* @interface UserProfile
* @description Represents the profile information of a user, including basic information and timestamps.
*
* @property {UserBasicInformation} basic_information - The basic information of the user.
* @property {Timestamp} created_at - The timestamp when the profile was created.
* @property {Timestamp} updated_at - The timestamp when the profile was last updated.
*
* @example
* // Example usage:
* const userProfile: UserProfile = {
* basic_information: {
* first_name: 'Jane',
* last_name: 'Doe',
* email: 'jane.doe@example.com',
* student_id: '1302194004'
* },
* created_at: Timestamp.now(),
* updated_at: Timestamp.now()
* };
*
* @remarks
* The timestamps can be useful for tracking the creation and modification dates of the user profile.
*
* @since 1.0.0
*/
export interface UserProfile {
basic_information: UserBasicInformation;
created_at: Timestamp;
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/utils/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { initializeApp } from 'firebase/app';
import { connectAuthEmulator, getAuth } from 'firebase/auth';
import { connectFirestoreEmulator, getFirestore } from 'firebase/firestore';
import { connectFunctionsEmulator, getFunctions } from 'firebase/functions';
import { connectStorageEmulator, getStorage } from 'firebase/storage';

export const VITE_FIREBASE_CONFIG = {
Expand All @@ -22,13 +23,15 @@ const NODE_ENV = import.meta.env.VITE_PROJECT_ENV;
const auth = getAuth(firebaseApp);
const firestore = getFirestore(firebaseApp);
const storage = getStorage(firebaseApp);
const functions = getFunctions(firebaseApp);

if (NODE_ENV === 'development') {
console.log('Using Emulator');

connectAuthEmulator(auth, `http://${HOST_NAME}:9099`);
connectFirestoreEmulator(firestore, HOST_NAME, 8080);
connectStorageEmulator(storage, HOST_NAME, 9199);
connectFunctionsEmulator(functions, HOST_NAME, 5001);
}

export { auth, firestore, storage, firebaseApp };
export { auth, firestore, storage, functions, firebaseApp };
Loading