update gitignore patterns, fix build scripts, update product API test files
This commit is contained in:
4
03_source/cms_backend/.gitignore
vendored
4
03_source/cms_backend/.gitignore
vendored
@@ -1,3 +1,7 @@
|
|||||||
|
**/*del
|
||||||
|
**/*bak
|
||||||
|
**/*copy*
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
@@ -15,3 +15,4 @@ yarn tsc
|
|||||||
|
|
||||||
yarn build
|
yarn build
|
||||||
|
|
||||||
|
echo "done"
|
||||||
|
@@ -1,43 +0,0 @@
|
|||||||
// src/app/api/product/createProduct/route.ts
|
|
||||||
// REQ0183 frontend product new
|
|
||||||
//
|
|
||||||
// PURPOSE:
|
|
||||||
// create product to db
|
|
||||||
//
|
|
||||||
// RULES:
|
|
||||||
// T.B.A.
|
|
||||||
//
|
|
||||||
|
|
||||||
import type { NextRequest } from 'next/server';
|
|
||||||
|
|
||||||
import { STATUS, response, handleError } from 'src/utils/response';
|
|
||||||
|
|
||||||
import { isDev } from 'src/constants';
|
|
||||||
|
|
||||||
import prisma from '../../../lib/prisma';
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
/** **************************************
|
|
||||||
* POST - Products
|
|
||||||
*************************************** */
|
|
||||||
export async function POST(req: NextRequest) {
|
|
||||||
const { data } = await req.json();
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (isDev) {
|
|
||||||
console.log({ data });
|
|
||||||
}
|
|
||||||
|
|
||||||
await prisma.productItem.create({ data });
|
|
||||||
|
|
||||||
if (isDev) {
|
|
||||||
console.log('create done');
|
|
||||||
}
|
|
||||||
|
|
||||||
return response({ hello: 'world' }, STATUS.OK);
|
|
||||||
} catch (error) {
|
|
||||||
console.log({ hello: 'world', data });
|
|
||||||
return handleError('Product - Create', error);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,51 +0,0 @@
|
|||||||
###
|
|
||||||
|
|
||||||
POST http://localhost:7272/api/product/createProduct
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"available": 99,
|
|
||||||
"category": "T-shirts",
|
|
||||||
"code": "PD-12345",
|
|
||||||
"colors": [
|
|
||||||
"Red"
|
|
||||||
],
|
|
||||||
"coverUrl": "",
|
|
||||||
"description": "this is description, 会員管理機能は、単なるデータ管理ツール以上の価値を持ちます。 企業は顧客の情報や動向を深く理解し、長期的な顧客関係の構築やロイヤルティの確立、そして迅速な市場変動への対応に直結します。 会員管理機能は、現代のビジネスにおいて企業の競争力を高める基盤として欠かせないものとなっています。",
|
|
||||||
"gender": [
|
|
||||||
"Men"
|
|
||||||
],
|
|
||||||
"images": [
|
|
||||||
"data:image/png;base64,C",
|
|
||||||
"data:image/png;base64,C"
|
|
||||||
],
|
|
||||||
"inventoryType": "test",
|
|
||||||
"name": "hello product",
|
|
||||||
"newLabel": {
|
|
||||||
"enabled": false,
|
|
||||||
"content": ""
|
|
||||||
},
|
|
||||||
"price": 99.99,
|
|
||||||
"priceSale": null,
|
|
||||||
"publish": "yes",
|
|
||||||
"quantity": 99,
|
|
||||||
"saleLabel": {
|
|
||||||
"enabled": false,
|
|
||||||
"content": ""
|
|
||||||
},
|
|
||||||
"sizes": [
|
|
||||||
"7"
|
|
||||||
],
|
|
||||||
"sku": "SK-122345",
|
|
||||||
"subDescription": "this is test sub-description",
|
|
||||||
"tags": [
|
|
||||||
"Travel",
|
|
||||||
"Finance"
|
|
||||||
],
|
|
||||||
"taxes": 0,
|
|
||||||
"totalRatings": 1,
|
|
||||||
"totalReviews": 1,
|
|
||||||
"totalSold": 1
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,8 @@
|
|||||||
|
###
|
||||||
|
|
||||||
|
PATCH http://localhost:7272/api/product/delete
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"productId" :"e99f09a7-dd88-49d5-b1c8-1daf80c2d7b06"
|
||||||
|
}
|
@@ -1,44 +0,0 @@
|
|||||||
// src/app/api/product/deleteProduct/route.ts
|
|
||||||
//
|
|
||||||
// PURPOSE:
|
|
||||||
// delete product from db by id
|
|
||||||
//
|
|
||||||
// RULES:
|
|
||||||
// T.B.A.
|
|
||||||
|
|
||||||
import type { NextRequest } from 'next/server';
|
|
||||||
|
|
||||||
import { logger } from 'src/utils/logger';
|
|
||||||
import { STATUS, response, handleError } from 'src/utils/response';
|
|
||||||
|
|
||||||
import prisma from '../../../lib/prisma';
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
/** **************************************
|
|
||||||
* handle Delete Products
|
|
||||||
*************************************** */
|
|
||||||
export async function DELETE(req: NextRequest) {
|
|
||||||
try {
|
|
||||||
const { searchParams } = req.nextUrl;
|
|
||||||
|
|
||||||
// RULES: productId must exist
|
|
||||||
const productId = searchParams.get('productId');
|
|
||||||
if (!productId) {
|
|
||||||
return response({ message: 'Product ID is required!' }, STATUS.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: productId confirmed exist, run below
|
|
||||||
const product = await prisma.productItem.delete({ where: { id: productId } });
|
|
||||||
|
|
||||||
if (!product) {
|
|
||||||
return response({ message: 'Product not found!' }, STATUS.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger('[Product] details', product.id);
|
|
||||||
|
|
||||||
return response({ product }, STATUS.OK);
|
|
||||||
} catch (error) {
|
|
||||||
return handleError('Product - Get details', error);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
###
|
|
||||||
|
|
||||||
DELETE http://localhost:7272/api/product/deleteProduct?productId=e99f09a7-dd88-49d5-b1c8-1daf80c2d7b06
|
|
@@ -1,129 +0,0 @@
|
|||||||
// src/app/api/product/saveProduct/route.ts
|
|
||||||
//
|
|
||||||
// PURPOSE:
|
|
||||||
// save product to db by id
|
|
||||||
//
|
|
||||||
// RULES:
|
|
||||||
// T.B.A.
|
|
||||||
|
|
||||||
import type { NextRequest } from 'next/server';
|
|
||||||
|
|
||||||
import { STATUS, response, handleError } from 'src/utils/response';
|
|
||||||
|
|
||||||
import prisma from '../../../lib/prisma';
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
/** **************************************
|
|
||||||
* GET - Products
|
|
||||||
*************************************** */
|
|
||||||
export async function PUT(req: NextRequest) {
|
|
||||||
// logger('[Product] list', products.length);
|
|
||||||
const { data } = await req.json();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const products = await prisma.productItem.updateMany({
|
|
||||||
data: {
|
|
||||||
name: data.name,
|
|
||||||
sku: data.sku,
|
|
||||||
code: data.code,
|
|
||||||
price: data.price,
|
|
||||||
taxes: data.taxes,
|
|
||||||
tags: data.tags,
|
|
||||||
sizes: data.sizes,
|
|
||||||
publish: data.publish,
|
|
||||||
gender: data.gender,
|
|
||||||
coverUrl: data.coverUrl,
|
|
||||||
images: data.images,
|
|
||||||
colors: data.colors,
|
|
||||||
quantity: data.quantity,
|
|
||||||
category: data.category,
|
|
||||||
available: data.available,
|
|
||||||
totalSold: data.totalSold,
|
|
||||||
description: data.description,
|
|
||||||
totalRatings: data.totalRatings,
|
|
||||||
totalReviews: data.totalReviews,
|
|
||||||
inventoryType: data.inventoryType,
|
|
||||||
subDescription: data.subDescription,
|
|
||||||
priceSale: data.priceSale,
|
|
||||||
//
|
|
||||||
newLabel: {
|
|
||||||
content: data.newLabel?.content || '',
|
|
||||||
enabled: data.newLabel?.enabled ?? false,
|
|
||||||
},
|
|
||||||
saleLabel: {
|
|
||||||
content: data.saleLabel?.content || '',
|
|
||||||
enabled: data.saleLabel?.enabled ?? false,
|
|
||||||
},
|
|
||||||
ratings: {
|
|
||||||
set: data.ratings.map((rating: { name: string; starCount: number; reviewCount: number }) => ({
|
|
||||||
name: rating.name,
|
|
||||||
starCount: rating.starCount,
|
|
||||||
reviewCount: rating.reviewCount,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
where: { id: data.id },
|
|
||||||
});
|
|
||||||
|
|
||||||
return response({ data }, STATUS.OK);
|
|
||||||
} catch (error) {
|
|
||||||
console.log({ data });
|
|
||||||
return handleError('Product - Get list', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IProductItem = {
|
|
||||||
id: string;
|
|
||||||
sku: string;
|
|
||||||
name: string;
|
|
||||||
code: string;
|
|
||||||
price: number;
|
|
||||||
taxes: number;
|
|
||||||
tags: string[];
|
|
||||||
sizes: string[];
|
|
||||||
publish: string;
|
|
||||||
gender: string[];
|
|
||||||
coverUrl: string;
|
|
||||||
images: string[];
|
|
||||||
colors: string[];
|
|
||||||
quantity: number;
|
|
||||||
category: string;
|
|
||||||
available: number;
|
|
||||||
totalSold: number;
|
|
||||||
description: string;
|
|
||||||
totalRatings: number;
|
|
||||||
totalReviews: number;
|
|
||||||
// createdAt: IDateValue;
|
|
||||||
inventoryType: string;
|
|
||||||
subDescription: string;
|
|
||||||
priceSale: number | null;
|
|
||||||
// reviews: IProductReview[];
|
|
||||||
newLabel: {
|
|
||||||
content: string;
|
|
||||||
enabled: boolean;
|
|
||||||
};
|
|
||||||
saleLabel: {
|
|
||||||
content: string;
|
|
||||||
enabled: boolean;
|
|
||||||
};
|
|
||||||
ratings: {
|
|
||||||
name: string;
|
|
||||||
starCount: number;
|
|
||||||
reviewCount: number;
|
|
||||||
}[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type IDateValue = string | number | null;
|
|
||||||
|
|
||||||
export type IProductReview = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
rating: number;
|
|
||||||
comment: string;
|
|
||||||
helpful: number;
|
|
||||||
avatarUrl: string;
|
|
||||||
postedAt: IDateValue;
|
|
||||||
isPurchased: boolean;
|
|
||||||
attachments?: string[];
|
|
||||||
};
|
|
@@ -1,51 +0,0 @@
|
|||||||
###
|
|
||||||
|
|
||||||
PUT http://localhost:7272/api/product/createProduct
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"available": 99,
|
|
||||||
"category": "T-shirts",
|
|
||||||
"code": "PD-12345",
|
|
||||||
"colors": [
|
|
||||||
"Red"
|
|
||||||
],
|
|
||||||
"coverUrl": "",
|
|
||||||
"description": "this is description, 会員管理機能は、単なるデータ管理ツール以上の価値を持ちます。 企業は顧客の情報や動向を深く理解し、長期的な顧客関係の構築やロイヤルティの確立、そして迅速な市場変動への対応に直結します。 会員管理機能は、現代のビジネスにおいて企業の競争力を高める基盤として欠かせないものとなっています。",
|
|
||||||
"gender": [
|
|
||||||
"Men"
|
|
||||||
],
|
|
||||||
"images": [
|
|
||||||
"data:image/png;base64,C",
|
|
||||||
"data:image/png;base64,C"
|
|
||||||
],
|
|
||||||
"inventoryType": "test",
|
|
||||||
"name": "hello product",
|
|
||||||
"newLabel": {
|
|
||||||
"enabled": false,
|
|
||||||
"content": ""
|
|
||||||
},
|
|
||||||
"price": 99.99,
|
|
||||||
"priceSale": null,
|
|
||||||
"publish": "yes",
|
|
||||||
"quantity": 99,
|
|
||||||
"saleLabel": {
|
|
||||||
"enabled": false,
|
|
||||||
"content": ""
|
|
||||||
},
|
|
||||||
"sizes": [
|
|
||||||
"7"
|
|
||||||
],
|
|
||||||
"sku": "SK-122345",
|
|
||||||
"subDescription": "this is test sub-description",
|
|
||||||
"tags": [
|
|
||||||
"Travel",
|
|
||||||
"Finance"
|
|
||||||
],
|
|
||||||
"taxes": 0,
|
|
||||||
"totalRatings": 1,
|
|
||||||
"totalReviews": 1,
|
|
||||||
"totalSold": 1
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,10 +1,10 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
PUT http://localhost:7272/api/product/createProduct
|
PUT http://localhost:7272/api/product/update
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"data": {
|
"productData": {
|
||||||
"available": 99,
|
"available": 99,
|
||||||
"category": "T-shirts",
|
"category": "T-shirts",
|
||||||
"code": "PD-12345",
|
"code": "PD-12345",
|
||||||
@@ -30,6 +30,7 @@ Content-Type: application/json
|
|||||||
"priceSale": null,
|
"priceSale": null,
|
||||||
"publish": "yes",
|
"publish": "yes",
|
||||||
"quantity": 99,
|
"quantity": 99,
|
||||||
|
"ratings":[],
|
||||||
"saleLabel": {
|
"saleLabel": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"content": ""
|
"content": ""
|
||||||
|
1
03_source/frontend/.gitignore
vendored
1
03_source/frontend/.gitignore
vendored
@@ -2,7 +2,6 @@
|
|||||||
**/*bak
|
**/*bak
|
||||||
**/*copy*
|
**/*copy*
|
||||||
|
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
@@ -11,3 +11,5 @@ yarn fm:fix
|
|||||||
yarn tsc
|
yarn tsc
|
||||||
|
|
||||||
yarn build
|
yarn build
|
||||||
|
|
||||||
|
echo "done"
|
||||||
|
@@ -5,7 +5,6 @@ npm i -D
|
|||||||
clear
|
clear
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
npm run dev
|
npm run dev
|
||||||
|
|
||||||
echo "restarting..."
|
echo "restarting..."
|
||||||
|
@@ -12,5 +12,4 @@ npm run format
|
|||||||
|
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
|
||||||
echo "done"
|
echo "done"
|
||||||
|
Reference in New Issue
Block a user