Skip to content

Commit

Permalink
refactor: reorganize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Jan 4, 2025
1 parent c817b42 commit 444b6f5
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 124 deletions.
4 changes: 2 additions & 2 deletions js/comment.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { dto } from './dto.js';
import { card } from './card.js';
import { like } from './like.js';
import { util } from './util.js';
import { theme } from './theme.js';
import { dto } from './http/dto.js';
import { session } from './session.js';
import { storage } from './storage.js';
import { pagination } from './pagination.js';
import { request, HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT } from './request.js';
import { request, HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT } from './http/request.js';

export const comment = (() => {

Expand Down
4 changes: 2 additions & 2 deletions js/dashboard/admin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { dto } from '../dto.js';
import { auth } from './auth.js';
import { util } from '../util.js';
import { theme } from '../theme.js';
import { dto } from '../http/dto.js';
import { navbar } from './navbar.js';
import { storage } from '../storage.js';
import { session } from '../session.js';
import { comment } from '../comment.js';
import { offline } from '../offline.js';
import { request, HTTP_GET, HTTP_PATCH, HTTP_PUT } from '../request.js';
import { request, HTTP_GET, HTTP_PATCH, HTTP_PUT } from '../http/request.js';

export const admin = (() => {

Expand Down
4 changes: 2 additions & 2 deletions js/dashboard/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { dto } from '../dto.js';
import { util } from '../util.js';
import { dto } from '../http/dto.js';
import { storage } from '../storage.js';
import { session } from '../session.js';
import { bootstrap } from '../bootstrap.js';
import { request, HTTP_GET } from '../request.js';
import { request, HTTP_GET } from '../http/request.js';

export const auth = (() => {

Expand Down
114 changes: 0 additions & 114 deletions js/dto.js

This file was deleted.

159 changes: 159 additions & 0 deletions js/http/dto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
export const dto = (() => {

/**
* @template T
* @param {number} code
* @param {T} data
* @param {string[]|null} error
* @returns {{code: number, data: T, error: string[]|null}}
*/
const baseResponse = (code, data, error) => {
return {
code,
data,
error,
};
};

/**
* @param {number} love
* @returns {{love: number}}
*/
const likeCommentResponse = (love = 0) => {
return {
love,
};
};

/**
* @param {{uuid: string, own: string, name: string, presence: boolean, comment: string, created_at: string}} postComment
* @returns {{uuid: string, own: string, name: string, presence: boolean, comment: string, is_admin: boolean, created_at: string, comments: postCommentResponse[], like: {love: number}}}
*/
const postCommentResponse = ({ uuid, own, name, presence, comment, created_at }) => {
let is_admin = false;
let comments = [];
let like = likeCommentResponse();

return {
uuid,
own,
name,
presence,
comment,
is_admin,
created_at,
comments,
like,
};
};

/**
* @param {{status: boolean}} status
* @returns {{status: boolean}}
*/
const statusResponse = ({ status }) => {
return {
status,
};
};

/**
* @param {{token: string}} token
* @returns {{token: string}}
*/
const tokenResponse = ({ token }) => {
return {
token,
};
};

/**
* @param {{uuid: string}} uuid
* @returns {{uuid: string}}
*/
const uuidResponse = ({ uuid }) => {
return {
uuid,
};
};

/**
* @param {{name: string, presence: boolean, comment: string, is_admin: boolean, created_at: string}} commentData
* @returns {{name: string, presence: boolean, comment: string, is_admin: boolean, created_at: string}}
*/
const commentResponse = ({ name, presence, comment, is_admin, created_at }) => {
return {
name,
presence,
comment,
is_admin,
created_at,
};
};

/**
* @param {string} uuid
* @param {boolean} show
* @returns {{uuid: string, show: boolean}}
*/
const commentShowMore = (uuid, show = false) => {
return {
uuid,
show,
};
};

/**
* @param {string} id
* @param {string} name
* @param {boolean} presence
* @param {string} comment
* @returns {{id: string, name: string, presence: boolean, comment: string}}
*/
const postCommentRequest = (id, name, presence, comment) => {
return {
id,
name,
presence,
comment,
};
};

/**
* @param {string} email
* @param {string} password
* @returns {{email: string, password: string}}
*/
const postSessionRequest = (email, password) => {
return {
email: email,
password: password,
};
};

/**
* @param {boolean} presence
* @param {string} comment
* @returns {{presence: boolean, comment: string}}
*/
const updateCommentRequest = (presence, comment) => {
return {
presence: presence,
comment: comment
};
};

return {
uuidResponse,
baseResponse,
tokenResponse,
statusResponse,
commentResponse,
likeCommentResponse,
postCommentResponse,
commentShowMore,
postCommentRequest,
postSessionRequest,
updateCommentRequest,
};
})();
File renamed without changes.
4 changes: 2 additions & 2 deletions js/like.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { dto } from './dto.js';
import { dto } from './http/dto.js';
import { storage } from './storage.js';
import { session } from './session.js';
import { confetti } from './confetti.js';
import { request, HTTP_PATCH, HTTP_POST } from './request.js';
import { request, HTTP_PATCH, HTTP_POST } from './http/request.js';

export const like = (() => {

Expand Down
4 changes: 2 additions & 2 deletions js/session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dto } from './dto.js';
import { dto } from './http/dto.js';
import { storage } from './storage.js';
import { request, HTTP_POST, HTTP_GET } from './request.js';
import { request, HTTP_POST, HTTP_GET } from './http/request.js';

export const session = (() => {

Expand Down

0 comments on commit 444b6f5

Please sign in to comment.