created models to separate layer in mvc
This commit is contained in:
parent
913e9150eb
commit
7a915e1931
|
|
@ -0,0 +1,69 @@
|
|||
import { randomUUID as uuidv4 } from 'node:crypto'
|
||||
import dayjs from 'dayjs'
|
||||
import mysql from '../../adapters/mysql.js'
|
||||
import {
|
||||
countEndpointsQuery,
|
||||
getEndpointsQuery,
|
||||
insertEndpointsQuery,
|
||||
modifyEndpointsQuery,
|
||||
deleteEndpointsQuery,
|
||||
softDeleteEndpointsQuery
|
||||
} from '../../repositories/authorization/endpointsRepository.js'
|
||||
|
||||
const getEndpointsModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {...rest, now}
|
||||
|
||||
return mysql
|
||||
.execute(getEndpointsQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(queryResult => queryResult.map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const countEndpointsModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {...rest, now}
|
||||
|
||||
return mysql
|
||||
.execute(countEndpointsQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(results => results[0].count)
|
||||
}
|
||||
|
||||
const insertEndpointsModel = ({conn, ...params}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const uuid = uuidv4()
|
||||
const paramsToInsert = {...params, uuid, now}
|
||||
return mysql
|
||||
.execute(insertEndpointsQuery(paramsToInsert), conn, paramsToInsert)
|
||||
.then(queryResult => queryResult[1].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
.catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
const modifyEndpointsModel = ({conn, ...params}) => {
|
||||
return mysql
|
||||
.execute(modifyEndpointsQuery(params), conn, params)
|
||||
.then(queryResult => queryResult[1].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const softDeleteEndpointsModel = ({uuid, deleted, deletedBy, conn}) => {
|
||||
const deletedData = deleted ? dayjs.utc(deleted).format('YYYY-MM-DD HH:mm:ss') : dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const params = {uuid, deletedBy, deleted: deletedData}
|
||||
|
||||
return mysql
|
||||
.execute(softDeleteEndpointsQuery(params), conn, params)
|
||||
}
|
||||
|
||||
const deleteEndpointsModel = ({uuid, conn}) => {
|
||||
return mysql
|
||||
.execute(deleteEndpointsQuery({uuid}), conn, {uuid})
|
||||
}
|
||||
|
||||
export {
|
||||
countEndpointsModel,
|
||||
getEndpointsModel,
|
||||
insertEndpointsModel,
|
||||
modifyEndpointsModel,
|
||||
softDeleteEndpointsModel,
|
||||
deleteEndpointsModel
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
import { randomUUID as uuidv4 } from 'node:crypto'
|
||||
import dayjs from 'dayjs'
|
||||
import mysql from '../../adapters/mysql.js'
|
||||
import {
|
||||
countPermissionsQuery,
|
||||
getPermissionsQuery,
|
||||
insertPermissionsQuery,
|
||||
modifyPermissionsQuery,
|
||||
softDeletePermissionsQuery
|
||||
} from '../../repositories/authorization/permissionsRepository.js'
|
||||
|
||||
const getPermissionModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {...rest, now}
|
||||
return mysql
|
||||
.execute(getPermissionsQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(queryResult => queryResult.map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const countPermissionModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {...rest, now}
|
||||
return mysql
|
||||
.execute(countPermissionsQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(results => results[0].count)
|
||||
}
|
||||
|
||||
const insertPermissionModel = ({conn, ...params}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const uuid = uuidv4()
|
||||
return mysql
|
||||
.execute(insertPermissionsQuery({...params, uuid, now}), conn, {...params, uuid, now})
|
||||
.then(queryResult => queryResult[1].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
.catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
const modifyPermissionModel = ({conn, ...params}) => {
|
||||
return mysql
|
||||
.execute(modifyPermissionsQuery(params), conn, params)
|
||||
.then(queryResult => queryResult[1].map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const softDeletePermissionModel = ({uuid, deleted, deletedBy, conn}) => {
|
||||
const deletedData = deleted ? dayjs.utc(deleted).format('YYYY-MM-DD HH:mm:ss') : dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const params = {uuid, deletedBy, deleted: deletedData}
|
||||
|
||||
return mysql
|
||||
.execute(softDeletePermissionsQuery(params), conn, params)
|
||||
}
|
||||
|
||||
export {
|
||||
getPermissionModel,
|
||||
countPermissionModel,
|
||||
modifyPermissionModel,
|
||||
insertPermissionModel,
|
||||
softDeletePermissionModel
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import { randomUUID as uuidv4 } from 'node:crypto'
|
||||
import dayjs from 'dayjs'
|
||||
import mysql from '../../adapters/mysql.js'
|
||||
import {
|
||||
countRoleQuery,
|
||||
getRoleQuery,
|
||||
insertRoleQuery,
|
||||
modifyRoleQuery,
|
||||
deleteRoleQuery,
|
||||
softDeleteRoleQuery
|
||||
} from '../../repositories/authorization/rolesRepository.js'
|
||||
|
||||
const getRoleModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
|
||||
return mysql
|
||||
.execute(getRoleQuery({...rest, now}), conn, {...rest, now})
|
||||
.then(queryResult => queryResult.map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const countRoleModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
|
||||
return mysql
|
||||
.execute(countRoleQuery({...rest, now}), conn, {...rest, now})
|
||||
.then(results => results[0].count)
|
||||
}
|
||||
|
||||
const insertRoleModel = ({conn, ...params}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const uuid = uuidv4()
|
||||
|
||||
return mysql.execute(insertRoleQuery({...params, uuid, now}), conn, {...params, uuid, now})
|
||||
.then(res => res[1].map(({id, created, deleted, createdBy, deletedBy, ...rest}) => ({...rest})))
|
||||
}
|
||||
|
||||
const modifyRoleModel = ({uuid, name, conn}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const params = {uuid, name, now}
|
||||
|
||||
return mysql
|
||||
.execute(modifyRoleQuery(params), conn, params)
|
||||
.then(res => res[1].map(({id, created, deleted, createdBy, deletedBy, ...rest}) => ({...rest})))
|
||||
}
|
||||
|
||||
const softDeleteRoleModel = ({uuid, deleted, deletedBy, conn}) => {
|
||||
const deletedData = deleted ? dayjs.utc(deleted).format('YYYY-MM-DD HH:mm:ss') :dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const params = {uuid, deletedBy, deleted: deletedData}
|
||||
|
||||
return mysql
|
||||
.execute(softDeleteRoleQuery(params), conn, params)
|
||||
}
|
||||
|
||||
export {
|
||||
getRoleModel,
|
||||
countRoleModel,
|
||||
insertRoleModel,
|
||||
modifyRoleModel,
|
||||
softDeleteRoleModel
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
import { randomUUID as uuidv4 } from 'node:crypto'
|
||||
import dayjs from 'dayjs'
|
||||
import mysql from '../../adapters/mysql.js'
|
||||
import {
|
||||
getRolesHasPermissionsQuery,
|
||||
countRolesHasPermissionsQuery,
|
||||
insertRolesHasPermissionsQuery,
|
||||
softDeleteRolesHasPermissionsQuery
|
||||
} from '../../repositories/authorization/roles_has_permissionsRepository.js'
|
||||
|
||||
const getRolesHasPermissionsModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = { ...rest, now }
|
||||
|
||||
return mysql
|
||||
.execute(getRolesHasPermissionsQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(results => results.map(({id, uuid, fk_role, fk_permission, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const countRolesHasPermissionsModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = { ...rest, now }
|
||||
|
||||
return mysql
|
||||
.execute(countRolesHasPermissionsQuery(params), conn, paramsToSearch)
|
||||
.then(results => results[0].count)
|
||||
}
|
||||
|
||||
const insertRolesHasPermissionsModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const uuid = uuidv4()
|
||||
const paramsToInsert = { ...rest, uuid, now }
|
||||
|
||||
return mysql
|
||||
.execute(insertRolesHasPermissionsQuery(paramsToInsert), conn, paramsToInsert)
|
||||
.then(results => results[1].map(({id, uuid, fk_role, fk_permission, created, deleted, createdBy, deletedBy, ...rest}) => ({...rest})))
|
||||
}
|
||||
|
||||
const softDeleteRolesHasPermissionsModel = ({conn, ...rest}) => {
|
||||
const deletedData = deleted ? dayjs.utc(deleted).format('YYYY-MM-DD HH:mm:ss') : dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const params = { ...rest, deleted: deletedData }
|
||||
|
||||
return mysql
|
||||
.execute(softDeleteRolesHasPermissionsQuery(params), conn, params)
|
||||
}
|
||||
|
||||
export {
|
||||
getRolesHasPermissionsModel,
|
||||
countRolesHasPermissionsModel,
|
||||
insertRolesHasPermissionsModel,
|
||||
softDeleteRolesHasPermissionsModel
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import { randomUUID as uuidv4 } from 'node:crypto'
|
||||
import dayjs from 'dayjs'
|
||||
import mysql from '../../adapters/mysql.js'
|
||||
import {
|
||||
countUserListQuery,
|
||||
getUserListQuery,
|
||||
insertUserQuery,
|
||||
modifyUserQuery,
|
||||
deleteUserQuery,
|
||||
softDeleteUserQuery
|
||||
} from '../../repositories/authorization/userRepository.js'
|
||||
|
||||
const getUserListModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {...rest, now}
|
||||
return mysql
|
||||
.execute(getUserListQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(queryResult => queryResult.map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const countUserListModel = ({conn, ...rest}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {...rest, now}
|
||||
return mysql
|
||||
.execute(countUserListQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(results => results[0].count)
|
||||
}
|
||||
|
||||
const getUserByUuidModel = ({conn, uuid}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const paramsToSearch = {uuid, now}
|
||||
return mysql
|
||||
.execute(getUserListQuery(paramsToSearch), conn, paramsToSearch)
|
||||
.then(queryResult => queryResult.map(({id, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const insertUserModel = ({conn, ...params}) => {
|
||||
const now = dayjs.utc().format('YYYY-MM-DD HH:mm:ss')
|
||||
const uuid = uuidv4()
|
||||
return mysql
|
||||
.execute(insertUserQuery({...params, uuid, now}), conn, {...params, uuid, now})
|
||||
.then(queryResult => queryResult[1].map(({id, password, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
.catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
|
||||
const modifyUserModel = ({conn, ...params}) => {
|
||||
return mysql
|
||||
.execute(modifyUserQuery(params), conn, params)
|
||||
.then(queryResult => queryResult[1].map(({id, password, created, deleted, createdBy, deletedBy, ...resultFiltered}) => resultFiltered))
|
||||
}
|
||||
|
||||
const softDeleteUserModel = ({uuid, deleted, deletedBy, conn}) => {
|
||||
const deletedData = deleted ? dayjs.utc(deleted).format('YYYY-MM-DD HH:mm:ss') : dayjs.utc.format('YYYY-MM-DD HH:mm:ss')
|
||||
const params = {uuid, deletedBy, deleted: deletedData}
|
||||
|
||||
return mysql
|
||||
.execute(softDeleteUserQuery(params), conn, params)
|
||||
}
|
||||
|
||||
export{
|
||||
countUserListModel,
|
||||
getUserListModel,
|
||||
softDeleteUserModel,
|
||||
insertUserModel,
|
||||
modifyUserModel
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue