Skip to content

Commit 68af38e

Browse files
chore: wip
1 parent e7dc3d5 commit 68af38e

File tree

11 files changed

+1983
-7
lines changed

11 files changed

+1983
-7
lines changed
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' | 'FailedJob' | 'Customer' | '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' | 'Product' | 'PaymentMethod' | 'PaymentTransaction' | 'Request' | 'GiftCard' | 'Order' | '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' | 'failed_jobs' | 'customers' | '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' | 'products' | 'payment_methods' | 'payment_transactions' | 'requests' | 'gift_cards' | 'orders' | 'coupons' | 'transactions' | 'loyalty_points' | 'jobs' | 'subscriptions' | 'payment_products' | 'loyalty_rewards' | 'errors' | 'product_categories'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type { Model } from '@stacksjs/types'
2+
import { schema } from '@stacksjs/validation'
3+
4+
export default {
5+
name: 'OrderItem',
6+
table: 'order_items',
7+
primaryKey: 'id',
8+
autoIncrement: true,
9+
10+
traits: {
11+
useTimestamps: true,
12+
},
13+
14+
belongsTo: ['Order', 'Product'],
15+
16+
attributes: {
17+
order_id: {
18+
required: true,
19+
order: 1,
20+
fillable: true,
21+
validation: {
22+
rule: schema.string(),
23+
},
24+
factory: () => '', // This will be filled by the Order factory
25+
},
26+
27+
product_id: {
28+
required: true,
29+
order: 2,
30+
fillable: true,
31+
validation: {
32+
rule: schema.number(),
33+
},
34+
factory: faker => faker.number.int({ min: 1, max: 50 }), // Assuming 50 products
35+
},
36+
37+
quantity: {
38+
required: true,
39+
default: 1,
40+
order: 3,
41+
fillable: true,
42+
validation: {
43+
rule: schema.number().min(1),
44+
message: {
45+
min: 'Quantity must be at least 1',
46+
},
47+
},
48+
factory: faker => faker.number.int({ min: 1, max: 5 }),
49+
},
50+
51+
price: {
52+
required: true,
53+
order: 4,
54+
fillable: true,
55+
validation: {
56+
rule: schema.number().min(0),
57+
message: {
58+
min: 'Price cannot be negative',
59+
},
60+
},
61+
factory: faker => faker.number.float({ min: 5, max: 50 }),
62+
},
63+
64+
special_instructions: {
65+
required: false,
66+
order: 5,
67+
fillable: true,
68+
validation: {
69+
rule: schema.string().nullable(),
70+
},
71+
factory: faker => faker.helpers.maybe(() => faker.lorem.sentence(), { probability: 0.2 }),
72+
},
73+
},
74+
} satisfies Model

storage/framework/orm/src/index.ts

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

2121
export { default as Order } from './Order'
2222

23+
export { default as OrderItem } from './OrderItem'
24+
2325
export { default as PaymentMethod } from './PaymentMethod'
2426

2527
export { default as PaymentProduct } from './PaymentProduct'

0 commit comments

Comments
 (0)