crud development
This commit is contained in:
parent
454cda29e5
commit
9da7f47cf6
7 changed files with 393 additions and 0 deletions
51
src/interfaces/call-api.ts
Normal file
51
src/interfaces/call-api.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import {
|
||||
Controller,
|
||||
Request,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
} from "tsoa";
|
||||
import axios from "axios";
|
||||
|
||||
class CallAPI {
|
||||
//Get
|
||||
public async GetData(request: any, @Path() path: any) {
|
||||
const token = request.headers.authorization;
|
||||
const url = process.env.API + path;
|
||||
try {
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
//Post
|
||||
public async PostData(request: any, @Path() path: any, sendData: any) {
|
||||
const token = request.headers.authorization;
|
||||
const url = process.env.API + path;
|
||||
try {
|
||||
const response = await axios.post(url, sendData, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CallAPI;
|
||||
81
src/interfaces/extension.ts
Normal file
81
src/interfaces/extension.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
class Extension {
|
||||
public static ToThaiMonth(value: number) {
|
||||
switch (value) {
|
||||
case 1:
|
||||
return "มกราคม";
|
||||
case 2:
|
||||
return "กุมภาพันธ์";
|
||||
case 3:
|
||||
return "มีนาคม";
|
||||
case 4:
|
||||
return "เมษายน";
|
||||
case 5:
|
||||
return "พฤษภาคม";
|
||||
case 6:
|
||||
return "มิถุนายน";
|
||||
case 7:
|
||||
return "กรกฎาคม";
|
||||
case 8:
|
||||
return "สิงหาคม";
|
||||
case 9:
|
||||
return "กันยายน";
|
||||
case 10:
|
||||
return "ตุลาคม";
|
||||
case 11:
|
||||
return "พฤศจิกายน";
|
||||
case 12:
|
||||
return "ธันวาคม";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static ToThaiYear(value: number) {
|
||||
if (value < 2400) return value + 543;
|
||||
else return value;
|
||||
}
|
||||
|
||||
public static ToCeYear(value: number) {
|
||||
if (value >= 2400) return value - 543;
|
||||
else return value;
|
||||
}
|
||||
|
||||
public static ToThaiNumber(value: string) {
|
||||
let arabicNumbers = "0123456789";
|
||||
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
||||
let result = "";
|
||||
for (let digit of value) {
|
||||
let index = arabicNumbers.indexOf(digit);
|
||||
if (index >= 0) {
|
||||
result += thaiNumbers[index];
|
||||
} else {
|
||||
result += digit;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ToThaiFullDate(value: Date) {
|
||||
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||
return (
|
||||
"วันที่ " +
|
||||
value.getDate() +
|
||||
" เดือน " +
|
||||
Extension.ToThaiMonth(value.getMonth() + 1) +
|
||||
" พ.ศ. " +
|
||||
yy
|
||||
);
|
||||
}
|
||||
|
||||
public static sumObjectValues(array: any, propertyName: any) {
|
||||
let sum = 0;
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i][propertyName] !== undefined) {
|
||||
sum += array[i][propertyName];
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
export default Extension;
|
||||
39
src/interfaces/storage-fs.ts
Normal file
39
src/interfaces/storage-fs.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
export interface StorageFolder {
|
||||
/**
|
||||
* @prop Full path to this folder. It is used as key as there are no files or directories at the same location.
|
||||
*/
|
||||
pathname: string;
|
||||
/**
|
||||
* @prop Directory / Folder name.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
createdAt: string | Date;
|
||||
createdBy: string | Date;
|
||||
}
|
||||
|
||||
export interface StorageFile {
|
||||
/**
|
||||
* @prop Full path to this folder. It is used as key as there are no files or directories at the same location.
|
||||
*/
|
||||
pathname: string;
|
||||
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
fileType: string;
|
||||
|
||||
title: string;
|
||||
description: string;
|
||||
author: string;
|
||||
category: string[];
|
||||
keyword: string[];
|
||||
metadata: Record<string, unknown>;
|
||||
|
||||
path: string;
|
||||
upload: boolean;
|
||||
|
||||
updatedAt: string | Date;
|
||||
updatedBy: string;
|
||||
createdAt: string | Date;
|
||||
createdBy: string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue