Skip to content

Commit 68fb184

Browse files
chore: wip
1 parent e1844e1 commit 68fb184

19 files changed

+2033
-6
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: 'ProductManufacturer Index',
6+
description: 'ProductManufacturer Index ORM Action',
7+
method: 'GET',
8+
async handle() {
9+
const results = ProductManufacturer.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 { ProductManufacturerRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
import { response } from '@stacksjs/router'
5+
6+
export default new Action({
7+
name: 'ProductManufacturer Show',
8+
description: 'ProductManufacturer Show ORM Action',
9+
method: 'GET',
10+
async handle(request: ProductManufacturerRequestType) {
11+
const id = request.getParam('id')
12+
13+
const model = await ProductManufacturer.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 { ProductManufacturerRequestType } from '@stacksjs/orm'
2+
import { Action } from '@stacksjs/actions'
3+
4+
import { response } from '@stacksjs/router'
5+
6+
export default new Action({
7+
name: 'ProductManufacturer Store',
8+
description: 'ProductManufacturer Store ORM Action',
9+
method: 'POST',
10+
async handle(request: ProductManufacturerRequestType) {
11+
await request.validate()
12+
const model = await ProductManufacturer.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' | 'OrderItem' | 'FailedJob' | 'Customer' | 'ProductReview' | 'Product' | 'PaymentMethod' | 'PaymentTransaction' | 'Request' | 'GiftCard' | 'Order' | 'Coupon' | 'Transaction' | 'LoyaltyPoint' | 'Job' | 'Subscription' | 'PaymentProduct' | 'LoyaltyReward' | 'Error' | 'ProductCategory'
1+
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'OrderItem' | 'FailedJob' | 'Customer' | 'ProductReview' | 'Product' | 'PaymentMethod' | 'PaymentTransaction' | 'Request' | 'GiftCard' | 'Order' | 'ProductManufacturer' | 'Coupon' | 'Transaction' | 'LoyaltyPoint' | 'Job' | 'Subscription' | 'PaymentProduct' | 'LoyaltyReward' | 'Error' | 'ProductCategory'
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' | 'order_items' | 'failed_jobs' | 'customers' | 'product_reviews' | 'products' | 'payment_methods' | 'payment_transactions' | 'requests' | 'gift_cards' | 'orders' | 'coupons' | 'transactions' | 'loyalty_points' | 'jobs' | 'subscriptions' | 'payment_products' | 'loyalty_rewards' | 'errors' | 'product_categories'
1+
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'order_items' | 'failed_jobs' | 'customers' | 'product_reviews' | 'products' | 'payment_methods' | 'payment_transactions' | 'requests' | 'gift_cards' | 'orders' | 'product_manufacturers' | 'coupons' | 'transactions' | 'loyalty_points' | 'jobs' | 'subscriptions' | 'payment_products' | 'loyalty_rewards' | 'errors' | 'product_categories'
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import type { Model } from '@stacksjs/types'
2+
import { schema } from '@stacksjs/validation'
3+
4+
export default {
5+
name: 'ProductManufacturer',
6+
table: 'product_manufacturers',
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', 'manufacturer', 'description', 'country', 'featured'],
15+
searchable: ['manufacturer', 'description', 'country'],
16+
sortable: ['manufacturer', 'country', 'created_at', 'updated_at'],
17+
filterable: ['country', 'featured'],
18+
},
19+
20+
useSeeder: {
21+
count: 30,
22+
},
23+
24+
useApi: {
25+
uri: 'product-manufacturers',
26+
routes: ['index', 'store', 'show'],
27+
},
28+
29+
observe: true,
30+
},
31+
32+
hasMany: ['Product'],
33+
34+
attributes: {
35+
manufacturer: {
36+
required: true,
37+
order: 1,
38+
fillable: true,
39+
validation: {
40+
rule: schema.string().maxLength(100),
41+
message: {
42+
maxLength: 'Manufacturer name must have a maximum of 100 characters',
43+
},
44+
},
45+
factory: faker => faker.company.name(),
46+
},
47+
48+
description: {
49+
required: false,
50+
order: 2,
51+
fillable: true,
52+
validation: {
53+
rule: schema.string().maxLength(2000),
54+
message: {
55+
maxLength: 'Description must have a maximum of 2000 characters',
56+
},
57+
},
58+
factory: faker => `${faker.company.catchPhrase()}. ${faker.company.buzzPhrase()}`,
59+
},
60+
61+
country: {
62+
required: true,
63+
order: 3,
64+
fillable: true,
65+
validation: {
66+
rule: schema.string().maxLength(100),
67+
message: {
68+
maxLength: 'Country must have a maximum of 100 characters',
69+
},
70+
},
71+
factory: faker => faker.location.country(),
72+
},
73+
74+
featured: {
75+
required: false,
76+
order: 4,
77+
fillable: true,
78+
validation: {
79+
rule: schema.boolean(),
80+
},
81+
factory: faker => faker.datatype.boolean({ probability: 0.2 }),
82+
},
83+
},
84+
85+
dashboard: {
86+
highlight: true,
87+
},
88+
} 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.post('orders', 'OrderStoreOrmAction')
4444

4545
route.get('orders/{id}', 'OrderShowOrmAction')
4646

47+
route.get('product-manufacturers', 'ProductManufacturerIndexOrmAction')
48+
49+
route.post('product-manufacturers', 'ProductManufacturerStoreOrmAction')
50+
51+
route.get('product-manufacturers/{id}', 'ProductManufacturerShowOrmAction')
52+
4753
route.get('coupons', 'CouponIndexOrmAction')
4854

4955
route.post('coupons', 'CouponStoreOrmAction')

storage/framework/orm/src/index.ts

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

3535
export { default as ProductCategory } from './ProductCategory'
3636

37+
export { default as ProductManufacturer } from './ProductManufacturer'
38+
3739
export { default as ProductReview } from './ProductReview'
3840

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

storage/framework/orm/src/models/Product.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ interface QueryOptions {
6060

6161
export class ProductModel {
6262
private readonly hidden: Array<keyof ProductJsonResponse> = []
63-
private readonly fillable: Array<keyof ProductJsonResponse> = ['name', 'description', 'price', 'image_url', 'is_available', 'inventory_count', 'category_id', 'preparation_time', 'allergens', 'nutritional_info', 'uuid', 'product_category_id']
63+
private readonly fillable: Array<keyof ProductJsonResponse> = ['name', 'description', 'price', 'image_url', 'is_available', 'inventory_count', 'category_id', 'preparation_time', 'allergens', 'nutritional_info', 'uuid', 'product_manufacturer_id', 'product_category_id']
6464
private readonly guarded: Array<keyof ProductJsonResponse> = []
6565
protected attributes = {} as ProductJsonResponse
6666
protected originalAttributes = {} as ProductJsonResponse

0 commit comments

Comments
 (0)