feat: optional props, update fields

This commit is contained in:
fPolic committed 2024-01-12 11:46:08 +01:00
1 parent b601212398
commit 1b882a90ed
8 files changed
+134 -77

No files matched your search

@@ -156,6 +156,15 @@
"nullable": false, "nullable": false,
"mappedType": "text" "mappedType": "text"
}, },
"provider_id": {
"name": "provider_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
},
"data": { "data": {
"name": "data", "name": "data",
"type": "jsonb", "type": "jsonb",
@@ -167,30 +176,30 @@
}, },
"name": { "name": {
"name": "name", "name": "name",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": false, "nullable": false,
"mappedType": "string" "mappedType": "text"
}, },
"type_detail": { "type_detail": {
"name": "type_detail", "name": "type_detail",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": false, "nullable": true,
"mappedType": "string" "mappedType": "text"
}, },
"description_detail": { "description_detail": {
"name": "description_detail", "name": "description_detail",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": false, "nullable": true,
"mappedType": "string" "mappedType": "text"
}, },
"metadata": { "metadata": {
"name": "metadata", "name": "metadata",
@@ -200,15 +209,6 @@
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "json" "mappedType": "json"
},
"provider_id": {
"name": "provider_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "text"
} }
}, },
"name": "payment-method-token", "name": "payment-method-token",
@@ -395,12 +395,12 @@
}, },
"is_selected": { "is_selected": {
"name": "is_selected", "name": "is_selected",
"type": "varchar(255)", "type": "boolean",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "string" "mappedType": "boolean"
}, },
"authorised_at": { "authorised_at": {
"name": "authorised_at", "name": "authorised_at",
@@ -480,50 +480,50 @@
"nullable": true, "nullable": true,
"mappedType": "decimal" "mappedType": "decimal"
}, },
"provider_id": { "currency_code": {
"name": "provider_id", "name": "currency_code",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": false, "nullable": false,
"mappedType": "string" "mappedType": "text"
}, },
"currency_code": { "provider_id": {
"name": "currency_code", "name": "provider_id",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": false,
"mappedType": "string" "mappedType": "text"
}, },
"cart_id": { "cart_id": {
"name": "cart_id", "name": "cart_id",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "string" "mappedType": "text"
}, },
"order_id": { "order_id": {
"name": "order_id", "name": "order_id",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "string" "mappedType": "text"
}, },
"customer_id": { "customer_id": {
"name": "customer_id", "name": "customer_id",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "string" "mappedType": "text"
}, },
"data": { "data": {
"name": "data", "name": "data",
@@ -706,12 +706,12 @@
}, },
"created_by": { "created_by": {
"name": "created_by", "name": "created_by",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "string" "mappedType": "text"
} }
}, },
"name": "capture", "name": "capture",
@@ -786,12 +786,12 @@
}, },
"created_by": { "created_by": {
"name": "created_by", "name": "created_by",
"type": "varchar(255)", "type": "text",
"unsigned": false, "unsigned": false,
"autoincrement": false, "autoincrement": false,
"primary": false, "primary": false,
"nullable": true, "nullable": true,
"mappedType": "string" "mappedType": "text"
} }
}, },
"name": "refund", "name": "refund",
@@ -1,6 +1,6 @@
import { Migration } from "@mikro-orm/migrations" import { Migration } from "@mikro-orm/migrations"
export class Migration20240111173302 extends Migration { export class Migration20240112104455 extends Migration {
async up(): Promise<void> { async up(): Promise<void> {
this.addSql( this.addSql(
'create table if not exists "payment-collection" ("id" text not null, "currency_code" text null, "amount" numeric not null, "authorized_amount" numeric null, "refunded_amount" numeric null, "region_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "completed_at" timestamptz null, "status" text check ("status" in (\'not_paid\', \'awaiting\', \'authorized\', \'partially_authorized\', \'canceled\')) not null default \'not_paid\', constraint "payment-collection_pkey" primary key ("id"));' 'create table if not exists "payment-collection" ("id" text not null, "currency_code" text null, "amount" numeric not null, "authorized_amount" numeric null, "refunded_amount" numeric null, "region_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "completed_at" timestamptz null, "status" text check ("status" in (\'not_paid\', \'awaiting\', \'authorized\', \'partially_authorized\', \'canceled\')) not null default \'not_paid\', constraint "payment-collection_pkey" primary key ("id"));'
@@ -10,7 +10,7 @@ export class Migration20240111173302 extends Migration {
) )
this.addSql( this.addSql(
'create table if not exists "payment-method-token" ("id" text not null, "data" jsonb null, "name" varchar(255) not null, "type_detail" varchar(255) not null, "description_detail" varchar(255) not null, "metadata" jsonb null, "provider_id" text not null, constraint "payment-method-token_pkey" primary key ("id"));' 'create table if not exists "payment-method-token" ("id" text not null, "provider_id" text not null, "data" jsonb null, "name" text not null, "type_detail" text null, "description_detail" text null, "metadata" jsonb null, constraint "payment-method-token_pkey" primary key ("id"));'
) )
this.addSql( this.addSql(
@@ -22,11 +22,11 @@ export class Migration20240111173302 extends Migration {
) )
this.addSql( this.addSql(
'create table if not exists "payment-session" ("id" text not null, "currency_code" text null, "amount" numeric not null, "provider_id" text not null, "data" jsonb null, "status" text check ("status" in (\'authorized\', \'pending\', \'requires_more\', \'error\', \'canceled\')) not null, "is_selected" varchar(255) null, "authorised_at" timestamptz null, "payment_collection_id" text not null, constraint "payment-session_pkey" primary key ("id"));' 'create table if not exists "payment-session" ("id" text not null, "currency_code" text null, "amount" numeric not null, "provider_id" text not null, "data" jsonb null, "status" text check ("status" in (\'authorized\', \'pending\', \'requires_more\', \'error\', \'canceled\')) not null, "is_selected" boolean null, "authorised_at" timestamptz null, "payment_collection_id" text not null, constraint "payment-session_pkey" primary key ("id"));'
) )
this.addSql( this.addSql(
'create table if not exists "payment" ("id" text not null, "amount" numeric not null, "authorized_amount" numeric null, "provider_id" varchar(255) not null, "currency_code" varchar(255) null, "cart_id" varchar(255) null, "order_id" varchar(255) null, "customer_id" varchar(255) null, "data" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "captured_at" timestamptz null, "canceled_at" timestamptz null, "payment_collection_id" text not null, "session_id" text not null, constraint "payment_pkey" primary key ("id"));' 'create table if not exists "payment" ("id" text not null, "amount" numeric not null, "authorized_amount" numeric null, "currency_code" text not null, "provider_id" text not null, "cart_id" text null, "order_id" text null, "customer_id" text null, "data" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "captured_at" timestamptz null, "canceled_at" timestamptz null, "payment_collection_id" text not null, "session_id" text not null, constraint "payment_pkey" primary key ("id"));'
) )
this.addSql( this.addSql(
'create index "IDX_payment_deleted_at" on "payment" ("deleted_at");' 'create index "IDX_payment_deleted_at" on "payment" ("deleted_at");'
@@ -36,11 +36,11 @@ export class Migration20240111173302 extends Migration {
) )
this.addSql( this.addSql(
'create table if not exists "capture" ("id" text not null, "amount" numeric not null, "payment_id" text not null, "created_at" timestamptz not null default now(), "created_by" varchar(255) null, constraint "capture_pkey" primary key ("id"));' 'create table if not exists "capture" ("id" text not null, "amount" numeric not null, "payment_id" text not null, "created_at" timestamptz not null default now(), "created_by" text null, constraint "capture_pkey" primary key ("id"));'
) )
this.addSql( this.addSql(
'create table if not exists "refund" ("id" text not null, "amount" numeric not null, "payment_id" text not null, "created_at" timestamptz not null default now(), "created_by" varchar(255) null, constraint "refund_pkey" primary key ("id"));' 'create table if not exists "refund" ("id" text not null, "amount" numeric not null, "payment_id" text not null, "created_at" timestamptz not null default now(), "created_by" text null, constraint "refund_pkey" primary key ("id"));'
) )
this.addSql( this.addSql(
+8 -3
View File
@@ -3,6 +3,7 @@ import {
Entity, Entity,
ManyToOne, ManyToOne,
OnInit, OnInit,
OptionalProps,
PrimaryKey, PrimaryKey,
Property, Property,
} from "@mikro-orm/core" } from "@mikro-orm/core"
@@ -10,8 +11,12 @@ import {
import { generateEntityId } from "@medusajs/utils" import { generateEntityId } from "@medusajs/utils"
import Payment from "./payment" import Payment from "./payment"
type OptionalCaptureProps = "created_by" | "created_at" | "completed_at"
@Entity({ tableName: "capture" }) @Entity({ tableName: "capture" })
export default class Capture { export default class Capture {
[OptionalProps]?: OptionalCaptureProps
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
id: string id: string
@@ -34,16 +39,16 @@ export default class Capture {
}) })
created_at: Date created_at: Date
@Property({ nullable: true }) @Property({ columnType: "text", nullable: true })
created_by: string | null created_by: string | null
@BeforeCreate() @BeforeCreate()
onCreate() { onCreate() {
this.id = generateEntityId(this.id, "capture") this.id = generateEntityId(this.id, "cap")
} }
@OnInit() @OnInit()
onInit() { onInit() {
this.id = generateEntityId(this.id, "capture") this.id = generateEntityId(this.id, "cap")
} }
} }
@@ -7,9 +7,11 @@ import {
ManyToMany, ManyToMany,
OneToMany, OneToMany,
OnInit, OnInit,
OptionalProps,
PrimaryKey, PrimaryKey,
Property, Property,
} from "@mikro-orm/core" } from "@mikro-orm/core"
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils" import { DALUtils, generateEntityId } from "@medusajs/utils"
import PaymentProvider from "./payment-provider" import PaymentProvider from "./payment-provider"
@@ -44,9 +46,19 @@ export enum PaymentCollectionStatus {
CANCELED = "canceled", CANCELED = "canceled",
} }
type OptionalPaymentCollectionProps =
| "currency_code"
| "authorized_amount"
| "refunded_amount"
| "region_id"
| "completed_at"
| DAL.SoftDeletableEntityDateColumns
@Entity({ tableName: "payment-collection" }) @Entity({ tableName: "payment-collection" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PaymentCollection { export default class PaymentCollection {
[OptionalProps]?: OptionalPaymentCollectionProps
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
id: string id: string
@@ -2,42 +2,51 @@ import {
BeforeCreate, BeforeCreate,
Entity, Entity,
OnInit, OnInit,
OptionalProps,
PrimaryKey, PrimaryKey,
Property, Property,
} from "@mikro-orm/core" } from "@mikro-orm/core"
import { generateEntityId } from "@medusajs/utils" import { generateEntityId } from "@medusajs/utils"
type OptionalPaymentMethodTokenProps =
| "data"
| "type_detail"
| "description_detail"
| "metadata"
@Entity({ tableName: "payment-method-token" }) @Entity({ tableName: "payment-method-token" })
export default class PaymentMethodToken { export default class PaymentMethodToken {
[OptionalProps]?: OptionalPaymentMethodTokenProps
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
id: string id: string
@Property({ columnType: "jsonb", nullable: true })
data?: Record<string, unknown> | null
@Property()
name: string
@Property()
type_detail: string
@Property()
description_detail: string
@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null
@Property({ columnType: "text" }) @Property({ columnType: "text" })
provider_id: string provider_id: string
@Property({ columnType: "jsonb", nullable: true })
data?: Record<string, unknown> | null
@Property({ columnType: "text" })
name: string
@Property({ columnType: "text", nullable: true })
type_detail: string | null
@Property({ columnType: "text", nullable: true })
description_detail: string | null
@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null
@BeforeCreate() @BeforeCreate()
onCreate() { onCreate() {
this.id = generateEntityId(this.id, "pmt") this.id = generateEntityId(this.id, "paymt")
} }
@OnInit() @OnInit()
onInit() { onInit() {
this.id = generateEntityId(this.id, "pmt") this.id = generateEntityId(this.id, "paymt")
} }
} }
+15 -3
View File
@@ -5,11 +5,14 @@ import {
ManyToOne, ManyToOne,
OneToOne, OneToOne,
OnInit, OnInit,
OptionalProps,
PrimaryKey, PrimaryKey,
Property, Property,
} from "@mikro-orm/core" } from "@mikro-orm/core"
import PaymentCollection from "./payment-collection" import { DAL } from "@medusajs/types"
import { generateEntityId } from "@medusajs/utils" import { generateEntityId } from "@medusajs/utils"
import PaymentCollection from "./payment-collection"
import Payment from "./payment" import Payment from "./payment"
/** /**
@@ -40,8 +43,17 @@ export enum PaymentSessionStatus {
CANCELED = "canceled", CANCELED = "canceled",
} }
type OptionalPaymentSessionProps =
| "currency_code"
| "data"
| "is_selected"
| "authorised_at"
| DAL.EntityDateColumns
@Entity({ tableName: "payment-session" }) @Entity({ tableName: "payment-session" })
export default class PaymentSession { export default class PaymentSession {
[OptionalProps]?: OptionalPaymentSessionProps
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
id: string id: string
@@ -65,7 +77,7 @@ export default class PaymentSession {
}) })
status: PaymentSessionStatus status: PaymentSessionStatus
@Property({ nullable: true }) @Property({ columnType: "boolean", nullable: true })
is_selected: boolean | null is_selected: boolean | null
@Property({ @Property({
@@ -84,7 +96,7 @@ export default class PaymentSession {
mappedBy: (payment) => payment.session, mappedBy: (payment) => payment.session,
cascade: ["soft-remove"] as any, cascade: ["soft-remove"] as any,
}) })
payment: Payment payment!: Payment
@BeforeCreate() @BeforeCreate()
onCreate() { onCreate() {
+21 -7
View File
@@ -7,9 +7,11 @@ import {
OneToMany, OneToMany,
OneToOne, OneToOne,
OnInit, OnInit,
OptionalProps,
PrimaryKey, PrimaryKey,
Property, Property,
} from "@mikro-orm/core" } from "@mikro-orm/core"
import { DAL } from "@medusajs/types"
import { DALUtils, generateEntityId } from "@medusajs/utils" import { DALUtils, generateEntityId } from "@medusajs/utils"
import Refund from "./refund" import Refund from "./refund"
@@ -17,9 +19,21 @@ import Capture from "./capture"
import PaymentSession from "./payment-session" import PaymentSession from "./payment-session"
import PaymentCollection from "./payment-collection" import PaymentCollection from "./payment-collection"
type OptionalPaymentProps =
| "authorized_amount"
| "cart_id"
| "order_id"
| "customer_id"
| "data"
| "captured_at"
| "canceled_at"
| DAL.SoftDeletableEntityDateColumns
@Entity({ tableName: "payment" }) @Entity({ tableName: "payment" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) @Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class Payment { export default class Payment {
[OptionalProps]?: OptionalPaymentProps
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
id: string id: string
@@ -36,19 +50,19 @@ export default class Payment {
}) })
authorized_amount: number | null authorized_amount: number | null
@Property() @Property({ columnType: "text" })
currency_code: string
@Property({ columnType: "text" })
provider_id: string provider_id: string
@Property({ nullable: true }) @Property({ columnType: "text", nullable: true })
currency_code: string | null
@Property({ nullable: true })
cart_id: string | null cart_id: string | null
@Property({ nullable: true }) @Property({ columnType: "text", nullable: true })
order_id: string | null order_id: string | null
@Property({ nullable: true }) @Property({ columnType: "text", nullable: true })
customer_id: string | null customer_id: string | null
@Property({ columnType: "jsonb", nullable: true }) @Property({ columnType: "jsonb", nullable: true })
+8 -3
View File
@@ -3,6 +3,7 @@ import {
Entity, Entity,
ManyToOne, ManyToOne,
OnInit, OnInit,
OptionalProps,
PrimaryKey, PrimaryKey,
Property, Property,
} from "@mikro-orm/core" } from "@mikro-orm/core"
@@ -10,8 +11,12 @@ import {
import { generateEntityId } from "@medusajs/utils" import { generateEntityId } from "@medusajs/utils"
import Payment from "./payment" import Payment from "./payment"
type OptionalRefundProps = "created_by" | "completed_at"
@Entity({ tableName: "refund" }) @Entity({ tableName: "refund" })
export default class Refund { export default class Refund {
[OptionalProps]?: OptionalRefundProps
@PrimaryKey({ columnType: "text" }) @PrimaryKey({ columnType: "text" })
id: string id: string
@@ -34,16 +39,16 @@ export default class Refund {
}) })
created_at: Date created_at: Date
@Property({ nullable: true }) @Property({ columnType: "text", nullable: true })
created_by: string | null created_by: string | null
@BeforeCreate() @BeforeCreate()
onCreate() { onCreate() {
this.id = generateEntityId(this.id, "refund") this.id = generateEntityId(this.id, "ref")
} }
@OnInit() @OnInit()
onInit() { onInit() {
this.id = generateEntityId(this.id, "refund") this.id = generateEntityId(this.id, "ref")
} }
} }