feat: add salePrice field to Product model and update related files

- Added salePrice field to Product model in Prisma schema and generated files.
- Updated Product scalar field enums in both TypeScript files.
- Modified aggregate output types to include salePrice.
- Enhanced input types for creating and updating products to support salePrice.
- Updated migration file to add salePrice column to Products table.
- Created DTOs for inventory management in POS module.
- Implemented POS controller and service with methods for stock and product categories.
This commit is contained in:
2025-12-14 20:34:07 +03:30
parent 9d7d94b5f8
commit 687c89c3e1
13 changed files with 360 additions and 25 deletions
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Products` ADD COLUMN `salePrice` DECIMAL(10, 2) NOT NULL DEFAULT 0.00;
+1
View File
@@ -70,6 +70,7 @@ model Product {
createdAt DateTime @default(now()) @db.Timestamp(0)
updatedAt DateTime @updatedAt @db.Timestamp(0)
deletedAt DateTime? @db.Timestamp(0)
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
brandId Int?
categoryId Int?
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
+43 -22
View File
@@ -33,40 +33,61 @@ async function main() {
if ((await prisma.productCategory.count()) === 0) {
await prisma.productCategory.createMany({
data: [{ name: 'دسته‌ی ۱' }, { name: 'دسته‌ی ۲' }, { name: 'دسته‌ی ۳' }],
data: Array.from({ length: 10 }, (_, i) => ({ name: `دسته‌ی ${i + 1}` })),
})
}
if ((await prisma.productBrand.count()) === 0) {
await prisma.productBrand.createMany({
data: [{ name: 'برند ۱' }, { name: 'برند ۲' }, { name: 'برند ۳' }],
data: Array.from({ length: 10 }, (_, i) => ({ name: `برند ${i + 1}` })),
})
}
if ((await prisma.supplier.count()) === 0) {
await prisma.supplier.createMany({
data: [
{
firstName: 'تامین‌',
lastName: 'کننده ۱',
mobileNumber: '09120000001',
email: 'supplier1@example.com',
},
{
firstName: 'تامین‌',
lastName: 'کننده ۲',
mobileNumber: '09120000002',
email: 'supplier2@example.com',
},
{
firstName: 'تامین‌',
lastName: 'کننده 3',
mobileNumber: '09120000003',
email: 'supplier3@example.com',
},
],
data: Array.from({ length: 20 }, (_, i) => ({
firstName: 'تامین‌',
lastName: `کننده ${i + 1}`,
mobileNumber: `0912000000${i + 1}`,
email: `supplier${i + 1}@example.com`,
})),
})
}
if ((await prisma.customer.count()) === 0) {
await prisma.customer.createMany({
data: Array.from({ length: 5 }, (_, i) => ({
firstName: 'مشتری',
lastName: `${i + 1}`,
mobileNumber: `0913000000${i + 1}`,
email: `customer${i + 1}@example.com`,
})),
})
}
if ((await prisma.product.count()) === 0) {
const categories = await prisma.productCategory.findMany()
const brands = await prisma.productBrand.findMany()
await prisma.product.createMany({
data: Array.from({ length: 100 }, (_, i) => ({
name: `کالای ${i + 1}`,
sku: `SKU-${1000 + i + 1}`,
salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
categoryId: categories[i % categories.length].id,
brandId: brands[i % brands.length].id,
})),
})
}
// const products = await prisma.product.findMany()
// for (const product of products) {
// await prisma.product.update({
// where: { id: product.id },
// data: {
// salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
// },
// })
// }
}
main()