This commit is contained in:
Viet An
2026-06-09 19:21:39 +07:00
parent 128993a93c
commit 7025fd8cd5
7 changed files with 212 additions and 758 deletions

View File

@@ -1,3 +1,5 @@
/** @typedef {import('~/utils/apis').ApiName} ApiName */
export default defineNuxtPlugin((nuxtApp) => {
const module = "application";
const mode = "dev";
@@ -18,6 +20,9 @@ export default defineNuxtPlugin((nuxtApp) => {
return name ? paths.find((v) => v.name === name).url : path;
};
/**
* @param {ApiName | ApiName[]} apiNames
*/
const findapi = function (name) {
const result = Array.isArray(name)
? apis.filter((v) => name.findIndex((x) => v.name === x) >= 0)
@@ -30,6 +35,9 @@ export default defineNuxtPlugin((nuxtApp) => {
return $copy(result);
};
/**
* @param {ApiName[]} apiNames
*/
const readyapi = function (apiNames) {
const apisWithReady = [];
apiNames.forEach((apiName) => {
@@ -69,6 +77,9 @@ export default defineNuxtPlugin((nuxtApp) => {
}
};
/**
* @param {ApiName} name
*/
const insertapi = async function (name, { data, values, notify = true } = {}) {
try {
const api = findapi(name);
@@ -115,6 +126,9 @@ export default defineNuxtPlugin((nuxtApp) => {
}
};
/**
* @param {ApiName} name
*/
const patchapi = async function (name, data, values, notify) {
try {
const api = findapi(name);
@@ -222,6 +236,9 @@ export default defineNuxtPlugin((nuxtApp) => {
return copy;
};
/**
* @param {ApiName} name
*/
const getdata = async function (name, { filter, params, first = false } = {}) {
const api = findapi(name);
if (params) api.params = params;
@@ -300,7 +317,9 @@ export default defineNuxtPlugin((nuxtApp) => {
return result;
};
// delete data
/**
* @param {ApiName} name
*/
const deleteapi = async function (name, id) {
try {
const found = findapi(name);