Skip to content

Commit 0b1eedd

Browse files
chore: wip
1 parent 1c8f764 commit 0b1eedd

File tree

16 files changed

+2099
-4
lines changed

16 files changed

+2099
-4
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Action } from '@stacksjs/actions'
2+
import { response } from '@stacksjs/router'
3+
4+
export default new Action({
5+
name: 'ProductUnit Index',
6+
description: 'ProductUnit Index ORM Action',
7+
method: 'GET',
8+
async handle() {
9+
const results = ProductUnit.all()
10+
11+
return response.json(results)
12+
},
13+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ProductUnitRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
import { response } from '@stacksjs/router'
5+
6+
export default new Action({
7+
name: 'ProductUnit Show',
8+
description: 'ProductUnit Show ORM Action',
9+
method: 'GET',
10+
async handle(request: ProductUnitRequestType) {
11+
const id = request.getParam('id')
12+
13+
const model = await ProductUnit.findOrFail(Number(id))
14+
15+
return response.json(model)
16+
},
17+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { ProductUnitRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
import { response } from '@stacksjs/router'
5+
6+
export default new Action({
7+
name: 'ProductUnit Store',
8+
description: 'ProductUnit Store ORM Action',
9+
method: 'POST',
10+
async handle(request: ProductUnitRequestType) {
11+
await request.validate()
12+
const model = await ProductUnit.create(request.all())
13+
14+
return response.json(model)
15+
},
16+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'Payment' | 'Manufacturer' | 'OrderItem' | 'Customer' | 'ProductReview' | 'Product' | 'ProductVariant' | 'GiftCard' | 'Order' | 'Coupon' | 'Transaction' | 'LoyaltyPoint' | 'ProductItem' | 'LoyaltyReward' | 'ProductCategory' | 'FailedJob' | 'PaymentMethod' | 'PaymentTransaction' | 'Request' | 'Job' | 'Subscription' | 'PaymentProduct' | 'Error'
1+
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'Payment' | 'Manufacturer' | 'OrderItem' | 'Customer' | 'ProductReview' | 'Product' | 'ProductVariant' | 'ProductUnit' | 'GiftCard' | 'Order' | 'Coupon' | 'Transaction' | 'LoyaltyPoint' | 'ProductItem' | 'LoyaltyReward' | 'ProductCategory' | 'FailedJob' | 'PaymentMethod' | 'PaymentTransaction' | 'Request' | 'Job' | 'Subscription' | 'PaymentProduct' | 'Error'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'payments' | 'manufacturers' | 'order_items' | 'customers' | 'product_reviews' | 'products' | 'product_variants' | 'gift_cards' | 'orders' | 'coupons' | 'transactions' | 'loyalty_points' | 'product_items' | 'loyalty_rewards' | 'product_categories' | 'failed_jobs' | 'payment_methods' | 'payment_transactions' | 'requests' | 'jobs' | 'subscriptions' | 'payment_products' | 'errors'
1+
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'payments' | 'manufacturers' | 'order_items' | 'customers' | 'product_reviews' | 'products' | 'product_variants' | 'product_units' | 'gift_cards' | 'orders' | 'coupons' | 'transactions' | 'loyalty_points' | 'product_items' | 'loyalty_rewards' | 'product_categories' | 'failed_jobs' | 'payment_methods' | 'payment_transactions' | 'requests' | 'jobs' | 'subscriptions' | 'payment_products' | 'errors'
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import type { Model } from '@stacksjs/types'
2+
import { schema } from '@stacksjs/validation'
3+
4+
export default {
5+
name: 'ProductUnit',
6+
table: 'product_units',
7+
primaryKey: 'id',
8+
autoIncrement: false, // Using UUID instead of auto-increment
9+
10+
traits: {
11+
useUuid: true,
12+
useTimestamps: true,
13+
useSearch: {
14+
displayable: ['id', 'name', 'abbreviation', 'type', 'description', 'is_default'],
15+
searchable: ['name', 'abbreviation', 'type', 'description'],
16+
sortable: ['name', 'type', 'created_at', 'updated_at'],
17+
filterable: ['type', 'is_default'],
18+
},
19+
20+
useSeeder: {
21+
count: 10,
22+
},
23+
24+
useApi: {
25+
uri: 'product-units',
26+
routes: ['index', 'store', 'show'],
27+
},
28+
29+
observe: true,
30+
},
31+
32+
belongsTo: ['Product'],
33+
34+
attributes: {
35+
name: {
36+
required: true,
37+
order: 1,
38+
fillable: true,
39+
validation: {
40+
rule: schema.string().maxLength(100),
41+
message: {
42+
maxLength: 'Name must have a maximum of 100 characters',
43+
},
44+
},
45+
factory: (faker) => {
46+
const units = ['Piece', 'Kilogram', 'Gram', 'Liter', 'Milliliter', 'Meter', 'Centimeter', 'Box', 'Pack', 'Pair']
47+
return faker.helpers.arrayElement(units)
48+
},
49+
},
50+
51+
abbreviation: {
52+
required: true,
53+
order: 2,
54+
fillable: true,
55+
validation: {
56+
rule: schema.string().maxLength(10),
57+
message: {
58+
maxLength: 'Abbreviation must have a maximum of 10 characters',
59+
},
60+
},
61+
factory: (faker) => {
62+
const abbrs = ['pc', 'kg', 'g', 'L', 'mL', 'm', 'cm', 'box', 'pk', 'pr']
63+
return faker.helpers.arrayElement(abbrs)
64+
},
65+
},
66+
67+
type: {
68+
required: true,
69+
order: 3,
70+
fillable: true,
71+
validation: {
72+
rule: schema.string(),
73+
message: {
74+
string: 'Type must be a string',
75+
},
76+
},
77+
factory: (faker) => {
78+
const types = ['Weight', 'Volume', 'Length', 'Quantity', 'Size']
79+
return faker.helpers.arrayElement(types)
80+
},
81+
},
82+
83+
description: {
84+
required: false,
85+
order: 4,
86+
fillable: true,
87+
validation: {
88+
rule: schema.string().maxLength(255),
89+
message: {
90+
maxLength: 'Description must have a maximum of 255 characters',
91+
},
92+
},
93+
factory: faker => faker.lorem.sentence(),
94+
},
95+
96+
is_default: {
97+
required: false,
98+
order: 5,
99+
fillable: true,
100+
validation: {
101+
rule: schema.boolean(),
102+
message: {
103+
boolean: 'Default status must be a boolean',
104+
},
105+
},
106+
factory: faker => faker.datatype.boolean(0.2), // 20% chance of being default
107+
},
108+
},
109+
110+
dashboard: {
111+
highlight: true,
112+
},
113+
} satisfies Model

storage/framework/orm/routes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ route.patch('product-variants/{id}', 'ProductVariantUpdateOrmAction')
4444

4545
route.delete('product-variants/{id}', 'ProductVariantDestroyOrmAction')
4646

47+
route.get('product-units', 'ProductUnitIndexOrmAction')
48+
49+
route.post('product-units', 'ProductUnitStoreOrmAction')
50+
51+
route.get('product-units/{id}', 'ProductUnitShowOrmAction')
52+
4753
route.get('gift-cards', 'GiftCardIndexOrmAction')
4854

4955
route.post('gift-cards', 'GiftCardStoreOrmAction')

storage/framework/orm/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export { default as ProductItem } from './ProductItem'
4242

4343
export { default as ProductReview } from './ProductReview'
4444

45+
export { default as ProductUnit } from './ProductUnit'
46+
4547
export { default as ProductVariant } from './ProductVariant'
4648

4749
export { default as Project } from './Project'

0 commit comments

Comments
 (0)