-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4590594
commit 65e4e80
Showing
19 changed files
with
517 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,96 @@ | ||
// attribute.controller.ts | ||
import { Controller, Get, Post, Put, Delete, Body, Param } from '@nestjs/common'; | ||
import {Request, Response} from 'express'; | ||
import { AttributeService } from '../services/attribute.service'; | ||
import { Attribute } from '../entities/Attribute'; | ||
|
||
@Controller('attributes') | ||
export class AttributeController { | ||
constructor(private readonly attributeService: AttributeService) {} | ||
|
||
@Post() | ||
create(@Body() data: Partial<Attribute>) { | ||
return this.attributeService.create(data); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.attributeService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: number) { | ||
return this.attributeService.findOne(id); | ||
} | ||
|
||
@Put(':id') | ||
update(@Param('id') id: number, @Body() data: Partial<Attribute>) { | ||
return this.attributeService.update(id, data); | ||
} | ||
|
||
@Delete(':id') | ||
delete(@Param('id') id: number) { | ||
return this.attributeService.delete(id); | ||
} | ||
import AppDataSource from '../config/ormconfig'; | ||
|
||
const attributeService = new AttributeService(); | ||
|
||
|
||
//create new attribute | ||
export const createAttribute = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attribute = await attributeService.create(req.body); | ||
res | ||
.status(201) | ||
.json({ success: true, message: "Attribute Created Successfully", data: attribute }); | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
|
||
//get all attributes | ||
export const getAllAttributes = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attributes = await attributeService.getAll(); | ||
res | ||
.status(200) | ||
.json({ success: true, message: "Attributes Retrieved Successfully", data: attributes }); | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
//get attribute by id | ||
export const getAttributeById = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attribute = await attributeService.getById(Number(req.params.id)); | ||
if (!attribute) { | ||
res | ||
.status(404) | ||
.json({ success: false, message: "Attribute Not Found" }); | ||
} else { | ||
res | ||
.status(200) | ||
.json({ success: true, message: "Attribute Retrieved Successfully", data: attribute }); | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
//update attribute | ||
export const updateAttribute = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attribute = await attributeService.update(Number(req.params.id), req.body) | ||
if (!attribute) { | ||
res | ||
.status(404) | ||
.json({ success: false, message: "Attribute Not Found" }); | ||
} else { | ||
res | ||
.status(200) | ||
.json({ success: true, message: "Attribute Updated Successfully", data: attribute }); | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
|
||
//delete attribute | ||
export const deleteAttribute = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const success = await attributeService.delete(Number(req.params.id)); | ||
if (!success) { | ||
res | ||
.status(404) | ||
.json({ success: false, message: "Attribute Not Found" }); | ||
} else { | ||
res | ||
.status(200) | ||
.send() | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,98 @@ | ||
import { Controller, Get, Post, Put, Delete, Body, Param } from '@nestjs/common'; | ||
import { AttributeValueService } from '../services/attributeValue.service'; | ||
import { AttributeValue } from '../entities/AttributeValue'; | ||
import {Request, Response} from "express"; | ||
import { AttributeValueService } from "../services/attributeValue.service"; | ||
|
||
@Controller('attribute-values') | ||
export class AttributeValueController { | ||
constructor(private readonly attributeValueService: AttributeValueService) {} | ||
const attributeValueService = new AttributeValueService(); | ||
|
||
@Post() | ||
create(@Body() data: Partial<AttributeValue>) { | ||
return this.attributeValueService.create(data); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.attributeValueService.findAll(); | ||
} | ||
//create new attribute value | ||
export const createAttributeValue = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attributeValue = await attributeValueService.create(req.body); | ||
if (!attributeValue) { | ||
res | ||
.status(400) | ||
.json({ success: false, message: "Attribute not found" }); | ||
} else { | ||
res | ||
.status(201) | ||
.json({ success: true, message: "Attribute Value Created Successfully", data: attributeValue }); | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: number) { | ||
return this.attributeValueService.findOne(id); | ||
} | ||
//get all attribute values | ||
export const getAllAttributesValues = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attributeValues = await attributeValueService.getAll(); | ||
res | ||
.status(200) | ||
.json({ success: true, message: "Attribute Values Retrieved Successfully", data: attributeValues }); | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
@Put(':id') | ||
update(@Param('id') id: number, @Body() data: Partial<AttributeValue>) { | ||
return this.attributeValueService.update(id, data); | ||
} | ||
//get attribute value by id | ||
export const getAttributeValueById = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attributeValue = await attributeValueService.getById(Number(req.params.id)); | ||
if (!attributeValue) { | ||
res | ||
.status(404) | ||
.json({ success: false, message: "Attribute Value Not Found" }); | ||
} else { | ||
res | ||
.status(200) | ||
.json({ success: true, message: "Attribute Value Retrieved Successfully", data: attributeValue }); | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
@Delete(':id') | ||
delete(@Param('id') id: number) { | ||
return this.attributeValueService.delete(id); | ||
} | ||
//update attribute value | ||
export const updateAttributeValue = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const attributeValue = await attributeValueService.update(Number(req.params.id), req.body) | ||
if (!attributeValue) { | ||
res | ||
.status(404) | ||
.json({ success: false, message: "Attribute Value Not Found" }); | ||
} else { | ||
res | ||
.status(200) | ||
.json({ success: true, message: "Attribute Value Updated Successfully", data: attributeValue }); | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} | ||
|
||
//delete attribute value | ||
export const deleteAttributeValue = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const success = await attributeValueService.delete(Number(req.params.id)); | ||
if (!success) { | ||
res | ||
.status(404) | ||
.json({ success: false, message: "Attribute Value Not Found" }); | ||
} else { | ||
res | ||
.status(204) | ||
.send() | ||
} | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error", error: error.message }); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Request, Response } from 'express'; | ||
import { ProductVariantAttributeService as ProductVariantAttributeServiceClass } from '../services/productVariantAttribute.service'; | ||
import AppDataSource from '../config/ormconfig'; | ||
|
||
const ProductVariantAttributeService = new ProductVariantAttributeServiceClass(); | ||
|
||
//create product variant attribute | ||
export const createProductVariantAttribute = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const productVariantAttribute = await ProductVariantAttributeService.create(req.body); | ||
if (!productVariantAttribute) { | ||
res.status(400).json({ success: false, message: 'Invalid productVariantId or attributeValueId' }); | ||
} else { | ||
res.status(201).json({ success: true, message: 'Product Variant Attribute Created Successfully', data: productVariantAttribute }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal Server Error', error: error.message }); | ||
} | ||
} | ||
|
||
|
||
//get all product variant attributes | ||
export const getAllProductVariantAttributes = async (_req: Request, res: Response): Promise<void> => { | ||
try { | ||
const productVariantAttributes = await ProductVariantAttributeService.getAll(); | ||
res.status(200).json({ success: true, message: 'Product Variant Attributes Retrieved', data: productVariantAttributes }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal Server Error', error: error.message }); | ||
} | ||
} | ||
|
||
//get product variant attribute by id | ||
export const getProductVariantAttributeById = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const productVariantAttribute = await ProductVariantAttributeService.getById(Number(req.params.id)); | ||
if (!productVariantAttribute) { | ||
res.status(404).json({ success: false, message: 'Product Variant Attribute not found' }); | ||
} else { | ||
res.status(200).json({ success: true, message: 'Product Variant Attribute Retrieved Successfully', data: productVariantAttribute }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal Server Error', error: error.message }); | ||
} | ||
} | ||
|
||
//update product variant attribute | ||
export const updateProductVariantAttribute = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const productVariantAttribute = await ProductVariantAttributeService.update(Number(req.params.id), req.body); | ||
if (!productVariantAttribute) { | ||
res.status(404).json({ success: false, message: 'Product Variant Attribute not found or invalid data' }); | ||
} else { | ||
res.status(200).json({ success: true, message: 'Product Variant Attribute Updated Successfully', data: productVariantAttribute }); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal Server Error', error: error.message }); | ||
} | ||
} | ||
|
||
//delete product variant attribute | ||
export const deleteProductVariantAttribute = async (req: Request, res: Response): Promise<void> => { | ||
try { | ||
const success = await ProductVariantAttributeService.delete(Number(req.params.id)); | ||
if (!success) { | ||
res.status(404).json({ success: false, message: 'Product Variant Attribute not found' }); | ||
} else { | ||
res.status(204).send(); | ||
} | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal Server Error', error: error.message }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.