1 import { model } from "@medusajs/framework/utils"
2 import Customer from "./customer"
3
4 const CustomerAddress = model
5 .define("CustomerAddress", {
6 id: model.id({ prefix: "cuaddr" }).primaryKey(),
7 address_name: model.text().searchable().nullable(),
8 is_default_shipping: model.boolean().default(false),
9 is_default_billing: model.boolean().default(false),
10 company: model.text().searchable().nullable(),
11 first_name: model.text().searchable().nullable(),
12 last_name: model.text().searchable().nullable(),
13 address_1: model.text().searchable().nullable(),
14 address_2: model.text().searchable().nullable(),
15 city: model.text().searchable().nullable(),
16 country_code: model.text().nullable(),
17 province: model.text().searchable().nullable(),
18 postal_code: model.text().searchable().nullable(),
19 phone: model.text().nullable(),
20 metadata: model.json().nullable(),
21 customer: model.belongsTo(() => Customer, {
22 mappedBy: "addresses",
23 }),
24 })
25 .indexes([
26 {
27 name: "IDX_customer_address_unique_customer_billing",
28 on: ["customer_id"],
29 unique: true,
30 where: '"is_default_billing" = true',
31 },
32 {
33 name: "IDX_customer_address_unique_customer_shipping",
34 on: ["customer_id"],
35 unique: true,
36 where: '"is_default_shipping" = true',
37 },
38 ])
39
40 export default CustomerAddress