Skip to content

Commit ead648f

Browse files
chore: wip
1 parent ec51d97 commit ead648f

File tree

8 files changed

+39
-50
lines changed

8 files changed

+39
-50
lines changed
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1+
// Import the CustomerTable type from the ORM
2+
import type {
3+
CustomerJsonResponse,
4+
CustomersTable,
5+
CustomerType,
6+
CustomerUpdate,
7+
NewCustomer,
8+
} from '../../orm/src/models/Customer'
9+
10+
// Re-export the types
11+
export type {
12+
CustomerJsonResponse,
13+
CustomersTable,
14+
CustomerType,
15+
CustomerUpdate,
16+
NewCustomer,
17+
}
18+
19+
// Define response structure for paginated customers
20+
export interface CustomerResponse {
21+
data: CustomerJsonResponse[]
22+
paging: {
23+
total_records: number
24+
page: number
25+
total_pages: number
26+
}
27+
next_cursor: number | null
28+
}
29+
130
// Define the input for creating a customer
231
export interface CreateCustomerInput {
332
name: string
433
email: string
534
phone: string
635
orders?: number
7-
totalSpent?: number
8-
lastOrder?: string
9-
status?: 'Active' | 'Inactive'
36+
total_spent?: number // Changed from totalSpent to match the schema
37+
last_order?: string // Changed from lastOrder to match the schema
38+
status?: string
1039
avatar?: string
1140
user_id?: number
1241
}
@@ -17,9 +46,9 @@ export interface UpdateCustomerInput {
1746
email?: string
1847
phone?: string
1948
orders?: number
20-
totalSpent?: number
21-
lastOrder?: string
22-
status?: 'Active' | 'Inactive'
49+
total_spent?: number // Changed from totalSpent to match the schema
50+
last_order?: string // Changed from lastOrder to match the schema
51+
status?: string
2352
avatar?: string
2453
user_id?: number
2554
}

storage/framework/defaults/models/Order.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ export default {
3434
hasMany: ['Order'],
3535

3636
attributes: {
37-
customer_id: {
38-
required: true,
39-
order: 1,
40-
fillable: true,
41-
validation: {
42-
rule: schema.string(),
43-
},
44-
factory: (faker: Faker) => faker.string.uuid(),
45-
},
46-
4737
status: {
4838
required: true,
4939
order: 2,

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export interface OrdersTable {
2525
user?: UserModel
2626
coupon_id?: number
2727
coupon?: CouponModel
28-
customer_id?: string
2928
status?: string
3029
total_amount?: number
3130
tax_amount?: number
@@ -76,7 +75,7 @@ interface QueryOptions {
7675

7776
export class OrderModel {
7877
private readonly hidden: Array<keyof OrderJsonResponse> = []
79-
private readonly fillable: Array<keyof OrderJsonResponse> = ['customer_id', 'status', 'total_amount', 'tax_amount', 'discount_amount', 'delivery_fee', 'tip_amount', 'order_type', 'delivery_address', 'special_instructions', 'estimated_delivery_time', 'applied_coupon_id', 'order_items', 'uuid', 'customer_id', 'gift_card_id', 'coupon_id']
78+
private readonly fillable: Array<keyof OrderJsonResponse> = ['status', 'total_amount', 'tax_amount', 'discount_amount', 'delivery_fee', 'tip_amount', 'order_type', 'delivery_address', 'special_instructions', 'estimated_delivery_time', 'applied_coupon_id', 'order_items', 'uuid', 'customer_id', 'gift_card_id', 'coupon_id']
8079
private readonly guarded: Array<keyof OrderJsonResponse> = []
8180
protected attributes: Partial<OrderJsonResponse> = {}
8281
protected originalAttributes: Partial<OrderJsonResponse> = {}
@@ -182,10 +181,6 @@ export class OrderModel {
182181
return this.attributes.uuid
183182
}
184183

185-
get customer_id(): string | undefined {
186-
return this.attributes.customer_id
187-
}
188-
189184
get status(): string | undefined {
190185
return this.attributes.status
191186
}
@@ -246,10 +241,6 @@ export class OrderModel {
246241
this.attributes.uuid = value
247242
}
248243

249-
set customer_id(value: string) {
250-
this.attributes.customer_id = value
251-
}
252-
253244
set status(value: string) {
254245
this.attributes.status = value
255246
}
@@ -1238,14 +1229,6 @@ export class OrderModel {
12381229
return instance
12391230
}
12401231

1241-
static whereCustomerId(value: string): OrderModel {
1242-
const instance = new OrderModel(null)
1243-
1244-
instance.selectFromQuery = instance.selectFromQuery.where('customer_id', '=', value)
1245-
1246-
return instance
1247-
}
1248-
12491232
static whereStatus(value: string): OrderModel {
12501233
const instance = new OrderModel(null)
12511234

@@ -1899,7 +1882,6 @@ export class OrderModel {
18991882
const output: Partial<OrderJsonResponse> = {
19001883

19011884
id: this.id,
1902-
customer_id: this.customer_id,
19031885
status: this.status,
19041886
total_amount: this.total_amount,
19051887
tax_amount: this.tax_amount,
@@ -1972,13 +1954,6 @@ export async function remove(id: number): Promise<void> {
19721954
.execute()
19731955
}
19741956

1975-
export async function whereCustomerId(value: string): Promise<OrderModel[]> {
1976-
const query = DB.instance.selectFrom('orders').where('customer_id', '=', value)
1977-
const results = await query.execute()
1978-
1979-
return results.map((modelItem: OrderModel) => new OrderModel(modelItem))
1980-
}
1981-
19821957
export async function whereStatus(value: string): Promise<OrderModel[]> {
19831958
const query = DB.instance.selectFrom('orders').where('status', '=', value)
19841959
const results = await query.execute()

storage/framework/requests/OrderRequest.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ interface CustomAttributes {
1313
}
1414
interface RequestDataOrder {
1515
id: number
16-
customer_id: string
1716
status: string
1817
total_amount: number
1918
tax_amount: number
@@ -34,7 +33,6 @@ interface RequestDataOrder {
3433
}
3534
export class OrderRequest extends Request<RequestDataOrder> implements OrderRequestType {
3635
public id = 1
37-
public customer_id = ''
3836
public status = ''
3937
public total_amount = 0
4038
public tax_amount = 0

storage/framework/server-auto-imports.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,4 @@
244244
"transactionRequest": true,
245245
"userRequest": true
246246
}
247-
}
247+
}

storage/framework/types/attributes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export interface Attributes {
7676
expiry_date: string
7777
last_used_date: string
7878
template_id: string
79-
customer_id: string
8079
total_amount: number
8180
tax_amount: number
8281
discount_amount: number

storage/framework/types/requests.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ export interface GiftCardRequestType extends Request {
483483

484484
interface RequestDataOrder {
485485
id: number
486-
customer_id: string
487486
status: string
488487
total_amount: number
489488
tax_amount: number
@@ -504,11 +503,10 @@ interface RequestDataOrder {
504503
}
505504
export interface OrderRequestType extends Request {
506505
validate: (attributes?: CustomAttributes) => void
507-
get: ((key: 'id') => number) & ((key: 'customer_id' | 'status' | 'order_type' | 'delivery_address' | 'special_instructions' | 'estimated_delivery_time' | 'applied_coupon_id' | 'order_items') => string) & ((key: 'total_amount' | 'tax_amount' | 'discount_amount' | 'delivery_fee' | 'tip_amount') => number) & ((key: 'customer_id') => string) & ((key: 'gift_card_id') => string) & ((key: 'coupon_id') => string)
506+
get: ((key: 'id') => number) & ((key: 'status' | 'order_type' | 'delivery_address' | 'special_instructions' | 'estimated_delivery_time' | 'applied_coupon_id' | 'order_items') => string) & ((key: 'total_amount' | 'tax_amount' | 'discount_amount' | 'delivery_fee' | 'tip_amount') => number) & ((key: 'customer_id') => string) & ((key: 'gift_card_id') => string) & ((key: 'coupon_id') => string)
508507

509508
all: () => RequestDataOrder
510509
id: number
511-
customer_id: string
512510
status: string
513511
total_amount: number
514512
tax_amount: number

storage/framework/types/server-auto-imports.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,4 @@ declare global {
244244
const teamRequest: typeof import('./../requests')['teamRequest']
245245
const transactionRequest: typeof import('./../requests')['transactionRequest']
246246
const userRequest: typeof import('./../requests')['userRequest']
247-
}
247+
}

0 commit comments

Comments
 (0)