Add SQLite support for easy setup (#336)
* Modifies schema to allow SQLite as a DB driver. SQLite is preinstalled in most OSes allowing for minimal prerequisites in the installation process. * Removes Redis dependency and replaces "real" redis instance with ioredis-mock this is not feature complete and errors are expected. * Updates medusa new command to only ask for Postgres credentials if the starter template has database_type === "postgres" in medusa-config.js * Small improvements to bin resolution * Improvements to endpoint stability
This commit is contained in:
1 parent
09d1b1a141
commit
1039d040e9
76 files changed
+2072
-523
No files matched your search
@@ -1,16 +1,39 @@
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
|
||||
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError"
|
||||
const TRANSACTION_STARTED = "TransactionAlreadyStartedError"
|
||||
const TRANSACTION_NOT_STARTED = "TransactionNotStartedError"
|
||||
|
||||
const API_ERROR = "api_error"
|
||||
const INVALID_REQUEST_ERROR = "invalid_request_error"
|
||||
const INVALID_STATE_ERROR = "invalid_state_error"
|
||||
|
||||
export default () => {
|
||||
return (err, req, res, next) => {
|
||||
const logger = req.scope.resolve("logger")
|
||||
logger.error(err.message)
|
||||
logger.error(err)
|
||||
|
||||
console.error(err)
|
||||
const errorType = err.type || err.name
|
||||
|
||||
const errObj = {
|
||||
code: err.code,
|
||||
type: err.type,
|
||||
message: err.message,
|
||||
}
|
||||
|
||||
let statusCode = 500
|
||||
switch (err.name) {
|
||||
case MedusaError.Types.DUPLICATE_ERROR:
|
||||
switch (errorType) {
|
||||
case QUERY_RUNNER_RELEASED:
|
||||
case TRANSACTION_STARTED:
|
||||
case TRANSACTION_NOT_STARTED:
|
||||
statusCode = 409
|
||||
errObj.code = INVALID_STATE_ERROR
|
||||
errObj.message =
|
||||
"The request conflicted with another request. You may retry the request with the provided Idempotency-Key."
|
||||
break
|
||||
case MedusaError.Types.DUPLICATE_ERROR:
|
||||
statusCode = 402
|
||||
errObj.code = INVALID_REQUEST_ERROR
|
||||
break
|
||||
case MedusaError.Types.NOT_ALLOWED:
|
||||
case MedusaError.Types.INVALID_DATA:
|
||||
@@ -21,14 +44,12 @@ export default () => {
|
||||
break
|
||||
case MedusaError.Types.DB_ERROR:
|
||||
statusCode = 500
|
||||
errObj.code = API_ERROR
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
res.status(statusCode).json({
|
||||
name: err.name,
|
||||
message: err.message,
|
||||
})
|
||||
res.status(statusCode).json(errObj)
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ describe("POST /admin/collections", () => {
|
||||
})
|
||||
|
||||
it("returns error details", () => {
|
||||
expect(subject.body.name).toEqual("invalid_data")
|
||||
expect(subject.body.type).toEqual("invalid_data")
|
||||
expect(subject.body.message[0].message).toEqual(`"title" is required`)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -135,7 +135,7 @@ describe("POST /admin/products", () => {
|
||||
})
|
||||
|
||||
it("returns error details", () => {
|
||||
expect(subject.body.name).toEqual("invalid_data")
|
||||
expect(subject.body.type).toEqual("invalid_data")
|
||||
expect(subject.body.message[0].message).toEqual(`"title" is required`)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -43,15 +43,14 @@ export default async (req, res) => {
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
await manager.transaction(async m => {
|
||||
await cartService
|
||||
.withTransaction(m)
|
||||
.addShippingMethod(id, value.option_id, value.data)
|
||||
const updated = await cartService.withTransaction(m).retrieve(id, {
|
||||
const txCartService = cartService.withTransaction(m)
|
||||
await txCartService.addShippingMethod(id, value.option_id, value.data)
|
||||
const updated = await txCartService.retrieve(id, {
|
||||
relations: ["payment_sessions"],
|
||||
})
|
||||
|
||||
if (updated.payment_sessions?.length) {
|
||||
await cartService.withTransaction(m).setPaymentSessions(id)
|
||||
await txCartService.setPaymentSessions(id)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -43,27 +43,27 @@ export default async (req, res) => {
|
||||
const lineItemService = req.scope.resolve("lineItemService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
let cart = await cartService.retrieve(id)
|
||||
|
||||
await manager.transaction(async m => {
|
||||
const line = await lineItemService.generate(
|
||||
value.variant_id,
|
||||
cart.region_id,
|
||||
value.quantity,
|
||||
{ metadata: value.metadata }
|
||||
)
|
||||
await cartService.withTransaction(m).addLineItem(id, line)
|
||||
const txCartService = cartService.withTransaction(m)
|
||||
const cart = await txCartService.retrieve(id)
|
||||
|
||||
const updated = await cartService.withTransaction(m).retrieve(id, {
|
||||
const line = await lineItemService
|
||||
.withTransaction(m)
|
||||
.generate(value.variant_id, cart.region_id, value.quantity, {
|
||||
metadata: value.metadata,
|
||||
})
|
||||
await txCartService.addLineItem(id, line)
|
||||
|
||||
const updated = await txCartService.retrieve(id, {
|
||||
relations: ["payment_sessions"],
|
||||
})
|
||||
|
||||
if (updated.payment_sessions?.length) {
|
||||
await cartService.withTransaction(m).setPaymentSessions(id)
|
||||
await txCartService.setPaymentSessions(id)
|
||||
}
|
||||
})
|
||||
|
||||
cart = await cartService.retrieve(id, {
|
||||
const cart = await cartService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
})
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("POST /store/customers", () => {
|
||||
})
|
||||
|
||||
it("returns product decorated", () => {
|
||||
expect(subject.body.name).toEqual("invalid_data")
|
||||
expect(subject.body.type).toEqual("invalid_data")
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import path from "path"
|
||||
import { spawn, execSync } from "child_process"
|
||||
import chokidar from "chokidar"
|
||||
|
||||
@@ -9,12 +10,13 @@ export default async function({ port, directory }) {
|
||||
args.shift()
|
||||
args.shift()
|
||||
|
||||
execSync("babel src -d dist", {
|
||||
const babelPath = path.join(directory, "node_modules", ".bin", "babel")
|
||||
execSync(`${babelPath} src -d dist`, {
|
||||
cwd: directory,
|
||||
stdio: ["ignore", process.stdout, process.stderr],
|
||||
})
|
||||
|
||||
const cliPath = "./node_modules/@medusajs/medusa/cli.js"
|
||||
const cliPath = path.join(directory, "node_modules", ".bin", "medusa")
|
||||
let child = spawn(cliPath, [`start`, ...args], {
|
||||
cwd: directory,
|
||||
env: process.env,
|
||||
@@ -26,7 +28,7 @@ export default async function({ port, directory }) {
|
||||
Logger.info(`${f} changed: restarting...`)
|
||||
child.kill("SIGINT")
|
||||
|
||||
execSync(`babel src -d dist`, {
|
||||
execSync(`./node_modules/.bin/babel src -d dist`, {
|
||||
cwd: directory,
|
||||
stdio: ["pipe", process.stdout, process.stderr],
|
||||
})
|
||||
|
||||
@@ -27,11 +27,13 @@ const t = async function({ directory, migrate, seedFile }) {
|
||||
}
|
||||
}
|
||||
|
||||
if (migrate) {
|
||||
const { configModule } = getConfigFile(directory, `medusa-config`)
|
||||
const dbType = configModule.projectConfig.database_type
|
||||
if (migrate && dbType !== "sqlite") {
|
||||
const migrationDirs = getMigrations(directory)
|
||||
const { configModule } = getConfigFile(directory, `medusa-config`)
|
||||
const connection = await createConnection({
|
||||
type: configModule.projectConfig.database_type,
|
||||
database: configModule.projectConfig.database_database,
|
||||
url: configModule.projectConfig.database_url,
|
||||
extra: configModule.projectConfig.database_extra || {},
|
||||
migrations: migrationDirs,
|
||||
|
||||
@@ -2,6 +2,7 @@ import "core-js/stable"
|
||||
import "regenerator-runtime/runtime"
|
||||
|
||||
import express from "express"
|
||||
import { track } from "medusa-telemetry"
|
||||
|
||||
import loaders from "../loaders"
|
||||
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
import { createConnection, Connection, DefaultNamingStrategy } from "typeorm"
|
||||
import { createConnection } from "typeorm"
|
||||
|
||||
import { ShortenedNamingStrategy } from "../utils/naming-strategy"
|
||||
|
||||
export default async ({ container, configModule }) => {
|
||||
const entities = container.resolve("db_entities")
|
||||
|
||||
const isSqlite = configModule.projectConfig.database_type === "sqlite"
|
||||
|
||||
const connection = await createConnection({
|
||||
type: configModule.projectConfig.database_type,
|
||||
url: configModule.projectConfig.database_url,
|
||||
database: configModule.projectConfig.database_database,
|
||||
extra: configModule.projectConfig.database_extra || {},
|
||||
entities,
|
||||
namingStrategy: new ShortenedNamingStrategy(),
|
||||
logging: configModule.projectConfig.database_logging || false,
|
||||
})
|
||||
|
||||
if (isSqlite) {
|
||||
await connection.query(`PRAGMA foreign_keys = OFF`)
|
||||
await connection.synchronize()
|
||||
await connection.query(`PRAGMA foreign_keys = ON`)
|
||||
}
|
||||
|
||||
return connection
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import { currencies } from "../utils/currencies"
|
||||
import { countries } from "../utils/countries"
|
||||
|
||||
const silentResolution = (container, name, logger) => {
|
||||
try {
|
||||
const resolved = container.resolve(name)
|
||||
@@ -29,11 +32,54 @@ const silentResolution = (container, name, logger) => {
|
||||
|
||||
export default async ({ container }) => {
|
||||
const storeService = container.resolve("storeService")
|
||||
const currencyRepository = container.resolve("currencyRepository")
|
||||
const countryRepository = container.resolve("countryRepository")
|
||||
const profileService = container.resolve("shippingProfileService")
|
||||
const logger = container.resolve("logger")
|
||||
|
||||
const entityManager = container.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
const countryRepo = manager.getCustomRepository(countryRepository)
|
||||
const hasCountries = await countryRepo.findOne()
|
||||
if (!hasCountries) {
|
||||
for (const c of countries) {
|
||||
const query = `INSERT INTO "country" ("iso_2", "iso_3", "num_code", "name", "display_name") VALUES ($1, $2, $3, $4, $5)`
|
||||
|
||||
const iso2 = c.alpha2.toLowerCase()
|
||||
const iso3 = c.alpha3.toLowerCase()
|
||||
const numeric = c.numeric
|
||||
const name = c.name.toUpperCase()
|
||||
const display = c.name
|
||||
|
||||
await manager.queryRunner.query(query, [
|
||||
iso2,
|
||||
iso3,
|
||||
numeric,
|
||||
name,
|
||||
display,
|
||||
])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
const currencyRepo = manager.getCustomRepository(currencyRepository)
|
||||
const hasCurrencies = await currencyRepo.findOne()
|
||||
if (!hasCurrencies) {
|
||||
for (const [_, c] of Object.entries(currencies)) {
|
||||
const query = `INSERT INTO "currency" ("code", "symbol", "symbol_native", "name") VALUES ($1, $2, $3, $4)`
|
||||
|
||||
const code = c.code.toLowerCase()
|
||||
const sym = c.symbol
|
||||
const nat = c.symbol_native
|
||||
const name = c.name
|
||||
|
||||
await manager.queryRunner.query(query, [code, sym, nat, name])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await storeService.withTransaction(manager).create()
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import express from "express"
|
||||
import session from "express-session"
|
||||
import cookieParser from "cookie-parser"
|
||||
import morgan from "morgan"
|
||||
@@ -18,8 +17,24 @@ export default async ({ app, configModule }) => {
|
||||
sameSite = "none"
|
||||
}
|
||||
|
||||
const RedisStore = createStore(session)
|
||||
const redisClient = redis.createClient(configModule.projectConfig.redis_url)
|
||||
let sessionOpts = {
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
cookieName: "session",
|
||||
proxy: true,
|
||||
secret: config.cookieSecret,
|
||||
cookie: {
|
||||
sameSite,
|
||||
secure,
|
||||
maxAge: 10 * 60 * 60 * 1000,
|
||||
},
|
||||
}
|
||||
|
||||
if (configModule.projectConfig.redis_url) {
|
||||
const RedisStore = createStore(session)
|
||||
const redisClient = redis.createClient(configModule.projectConfig.redis_url)
|
||||
sessionOpts.store = new RedisStore({ client: redisClient })
|
||||
}
|
||||
|
||||
app.set("trust proxy", 1)
|
||||
app.use(
|
||||
@@ -28,21 +43,7 @@ export default async ({ app, configModule }) => {
|
||||
})
|
||||
)
|
||||
app.use(cookieParser())
|
||||
app.use(
|
||||
session({
|
||||
store: new RedisStore({ client: redisClient }),
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
cookieName: "session",
|
||||
proxy: true,
|
||||
secret: config.cookieSecret,
|
||||
cookie: {
|
||||
sameSite,
|
||||
secure,
|
||||
maxAge: 10 * 60 * 60 * 1000,
|
||||
},
|
||||
})
|
||||
)
|
||||
app.use(session(sessionOpts))
|
||||
|
||||
app.get("/health", (req, res) => {
|
||||
res.status(200).send("OK")
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { createContainer, asValue } from "awilix"
|
||||
import Redis from "ioredis"
|
||||
import requestIp from "request-ip"
|
||||
import { getManager } from "typeorm"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
import { track } from "medusa-telemetry"
|
||||
|
||||
import expressLoader from "./express"
|
||||
import redisLoader from "./redis"
|
||||
import databaseLoader from "./database"
|
||||
import repositoriesLoader from "./repositories"
|
||||
import apiLoader from "./api"
|
||||
@@ -18,10 +18,7 @@ import defaultsLoader from "./defaults"
|
||||
import Logger from "./logger"
|
||||
|
||||
export default async ({ directory: rootDirectory, expressApp }) => {
|
||||
const { configModule, configFilePath } = getConfigFile(
|
||||
rootDirectory,
|
||||
`medusa-config`
|
||||
)
|
||||
const { configModule } = getConfigFile(rootDirectory, `medusa-config`)
|
||||
|
||||
const container = createContainer()
|
||||
container.registerAdd = function(name, registration) {
|
||||
@@ -40,10 +37,6 @@ export default async ({ directory: rootDirectory, expressApp }) => {
|
||||
return this
|
||||
}.bind(container)
|
||||
|
||||
// Economical way of dealing with redis clients
|
||||
const client = new Redis(configModule.projectConfig.redis_url)
|
||||
const subscriber = new Redis(configModule.projectConfig.redis_url)
|
||||
|
||||
// Add additional information to context of request
|
||||
expressApp.use((req, res, next) => {
|
||||
const ipAddress = requestIp.getClientIp(req)
|
||||
@@ -57,11 +50,11 @@ export default async ({ directory: rootDirectory, expressApp }) => {
|
||||
})
|
||||
|
||||
container.register({
|
||||
redisClient: asValue(client),
|
||||
redisSubscriber: asValue(subscriber),
|
||||
logger: asValue(Logger),
|
||||
})
|
||||
|
||||
await redisLoader({ container, configModule, logger: Logger })
|
||||
|
||||
const modelsActivity = Logger.activity("Initializing models")
|
||||
track("MODELS_INIT_STARTED")
|
||||
modelsLoader({ container, activityId: modelsActivity })
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { asValue } from "awilix"
|
||||
import RealRedis from "ioredis"
|
||||
import FakeRedis from "ioredis-mock"
|
||||
|
||||
const redisLoader = async ({ container, configModule, logger }) => {
|
||||
if (configModule.projectConfig.redis_url) {
|
||||
// Economical way of dealing with redis clients
|
||||
const client = new RealRedis(configModule.projectConfig.redis_url)
|
||||
const subscriber = new RealRedis(configModule.projectConfig.redis_url)
|
||||
|
||||
container.register({
|
||||
redisClient: asValue(client),
|
||||
redisSubscriber: asValue(subscriber),
|
||||
})
|
||||
} else {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
logger.warn(
|
||||
`No Redis url was provided - using Medusa in production without a proper Redis instance is not recommended`
|
||||
)
|
||||
}
|
||||
|
||||
logger.info("Using fake Redis")
|
||||
|
||||
// Economical way of dealing with redis clients
|
||||
const client = new FakeRedis()
|
||||
|
||||
container.register({
|
||||
redisClient: asValue(client),
|
||||
redisSubscriber: asValue(client),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default redisLoader
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Customer } from "./customer"
|
||||
import { Country } from "./country"
|
||||
@@ -90,16 +91,16 @@ export class Address {
|
||||
@Column({ nullable: true })
|
||||
phone: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -102,6 +102,7 @@ import {
|
||||
BeforeUpdate,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Region } from "./region"
|
||||
import { Address } from "./address"
|
||||
@@ -223,30 +224,30 @@ export class Cart {
|
||||
)
|
||||
shipping_methods: ShippingMethod[]
|
||||
|
||||
@Column({ type: "enum", enum: CartType, default: "default" })
|
||||
@DbAwareColumn({ type: "enum", enum: CartType, default: "default" })
|
||||
type: boolean
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
completed_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
idempotency_key: string
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
context: any
|
||||
|
||||
|
||||
// Total fields
|
||||
shipping_total: number
|
||||
discount_total: number
|
||||
|
||||
@@ -14,6 +14,8 @@ import { ulid } from "ulid"
|
||||
|
||||
import { ClaimItem } from "./claim-item"
|
||||
|
||||
import { DbAwareColumn, resolveDbType } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class ClaimImage {
|
||||
@PrimaryColumn()
|
||||
@@ -33,16 +35,16 @@ export class ClaimImage {
|
||||
@Column()
|
||||
url: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { LineItem } from "./line-item"
|
||||
import { ClaimImage } from "./claim-image"
|
||||
@@ -67,7 +68,7 @@ export class ClaimItem {
|
||||
@JoinColumn({ name: "variant_id" })
|
||||
variant: ProductVariant
|
||||
|
||||
@Column({ type: "enum", enum: ClaimReason })
|
||||
@DbAwareColumn({ type: "enum", enum: ClaimReason })
|
||||
reason: ClaimReason
|
||||
|
||||
@Column({ nullable: true })
|
||||
@@ -90,16 +91,16 @@ export class ClaimItem {
|
||||
})
|
||||
tags: ClaimTag[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
import { LineItem } from "./line-item"
|
||||
@@ -50,14 +51,14 @@ export class ClaimOrder {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({
|
||||
@DbAwareColumn({
|
||||
type: "enum",
|
||||
enum: ClaimPaymentStatus,
|
||||
default: ClaimPaymentStatus.NA,
|
||||
})
|
||||
payment_status: ClaimPaymentStatus
|
||||
|
||||
@Column({
|
||||
@DbAwareColumn({
|
||||
type: "enum",
|
||||
enum: ClaimFulfillmentStatus,
|
||||
default: ClaimFulfillmentStatus.NOT_FULFILLED,
|
||||
@@ -77,7 +78,7 @@ export class ClaimOrder {
|
||||
)
|
||||
additional_items: LineItem[]
|
||||
|
||||
@Column({ type: "enum", enum: ClaimType })
|
||||
@DbAwareColumn({ type: "enum", enum: ClaimType })
|
||||
type: ClaimType
|
||||
|
||||
@Index()
|
||||
@@ -122,22 +123,22 @@ export class ClaimOrder {
|
||||
@Column({ type: "int", nullable: true })
|
||||
refund_amount: number
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
canceled_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "boolean", nullable: true})
|
||||
@Column({ type: "boolean", nullable: true })
|
||||
no_notification: Boolean
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class ClaimTag {
|
||||
@@ -22,16 +23,16 @@ export class ClaimTag {
|
||||
@Column()
|
||||
value: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Address } from "./address"
|
||||
import { Order } from "./order"
|
||||
@@ -60,16 +61,16 @@ export class Customer {
|
||||
)
|
||||
orders: Order[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Product } from "./product"
|
||||
|
||||
@@ -33,7 +34,7 @@ export class DiscountRule {
|
||||
@Column({ nullable: true })
|
||||
description: string
|
||||
|
||||
@Column({
|
||||
@DbAwareColumn({
|
||||
type: "enum",
|
||||
enum: DiscountRuleType,
|
||||
})
|
||||
@@ -42,7 +43,7 @@ export class DiscountRule {
|
||||
@Column()
|
||||
value: number
|
||||
|
||||
@Column({
|
||||
@DbAwareColumn({
|
||||
type: "enum",
|
||||
enum: AllocationType,
|
||||
nullable: true,
|
||||
@@ -63,16 +64,16 @@ export class DiscountRule {
|
||||
})
|
||||
valid_for: Product[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { DiscountRule } from "./discount-rule"
|
||||
import { Region } from "./region"
|
||||
@@ -48,10 +49,13 @@ export class Discount {
|
||||
@JoinColumn({ name: "parent_discount_id" })
|
||||
parent_discount: Discount
|
||||
|
||||
@Column({ type: "timestamptz", default: () => "CURRENT_TIMESTAMP" })
|
||||
@Column({
|
||||
type: resolveDbType("timestamptz"),
|
||||
default: () => "CURRENT_TIMESTAMP",
|
||||
})
|
||||
starts_at: Date
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
ends_at: Date
|
||||
|
||||
@ManyToMany(() => Region, { cascade: true })
|
||||
@@ -74,16 +78,16 @@ export class Discount {
|
||||
@Column({ default: 0 })
|
||||
usage_count: number
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,12 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import {
|
||||
resolveDbType,
|
||||
resolveDbGenerationStrategy,
|
||||
DbAwareColumn,
|
||||
} from "../utils/db-aware-column"
|
||||
import { manualAutoIncrement } from "../utils/manual-auto-increment"
|
||||
|
||||
import { Cart } from "./cart"
|
||||
import { Order } from "./order"
|
||||
@@ -25,12 +31,12 @@ export class DraftOrder {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({ type: "enum", enum: DraftOrderStatus, default: "open" })
|
||||
@DbAwareColumn({ type: "enum", enum: DraftOrderStatus, default: "open" })
|
||||
status: DraftOrderStatus
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
@Generated("increment")
|
||||
@Generated(resolveDbGenerationStrategy("increment"))
|
||||
display_id: number
|
||||
|
||||
@Index()
|
||||
@@ -49,32 +55,37 @@ export class DraftOrder {
|
||||
@JoinColumn({ name: "order_id" })
|
||||
order: Order
|
||||
|
||||
@Column({ nullable: true, type: "timestamptz" })
|
||||
@Column({ nullable: true, type: resolveDbType("timestamptz") })
|
||||
canceled_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
completed_at: Date
|
||||
|
||||
@Column({ nullable: true})
|
||||
@Column({ nullable: true })
|
||||
no_notification_order: boolean
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
idempotency_key: string
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
const id = ulid()
|
||||
this.id = `dorder_${id}`
|
||||
private async beforeInsert() {
|
||||
if (!this.id) {
|
||||
const id = ulid()
|
||||
this.id = `dorder_${id}`
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === "development" && !this.display_id) {
|
||||
this.display_id = await manualAutoIncrement("draft_order")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Order } from "./order"
|
||||
import { FulfillmentProvider } from "./fulfillment-provider"
|
||||
@@ -62,7 +63,7 @@ export class Fulfillment {
|
||||
@JoinColumn({ name: "order_id" })
|
||||
order: Order
|
||||
|
||||
@Column({ type: "boolean", nullable: true})
|
||||
@Column({ type: "boolean", nullable: true })
|
||||
no_notification: Boolean
|
||||
|
||||
@Index()
|
||||
@@ -87,25 +88,25 @@ export class Fulfillment {
|
||||
)
|
||||
tracking_links: TrackingLink[]
|
||||
|
||||
@Column({ type: "jsonb", default: [] })
|
||||
@DbAwareColumn({ type: "jsonb", default: [] })
|
||||
tracking_numbers: string[]
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
shipped_at: Date
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
canceled_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType } from "../utils/db-aware-column"
|
||||
|
||||
import { GiftCard } from "./gift-card"
|
||||
import { Order } from "./order"
|
||||
@@ -38,7 +39,7 @@ export class GiftCardTransaction {
|
||||
@Column("int")
|
||||
amount: number
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Region } from "./region"
|
||||
import { Order } from "./order"
|
||||
@@ -50,21 +51,21 @@ export class GiftCard {
|
||||
is_disabled: boolean
|
||||
|
||||
@Column({
|
||||
type: "timestamptz",
|
||||
type: resolveDbType("timestamptz"),
|
||||
nullable: true,
|
||||
})
|
||||
ends_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class IdempotencyKey {
|
||||
@@ -17,16 +18,16 @@ export class IdempotencyKey {
|
||||
@Column()
|
||||
idempotency_key: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@DbAwareColumn({ type: "timestamptz", nullable: true })
|
||||
locked_at: Date
|
||||
|
||||
@Column({ nullable: true })
|
||||
request_method: string
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
request_params: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
@@ -35,7 +36,7 @@ export class IdempotencyKey {
|
||||
@Column({ type: "int", nullable: true })
|
||||
response_code: number
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
response_body: any
|
||||
|
||||
@Column({ default: "started" })
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class Image {
|
||||
@@ -17,16 +18,16 @@ export class Image {
|
||||
@Column()
|
||||
url: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Swap } from "./swap"
|
||||
import { Cart } from "./cart"
|
||||
@@ -115,13 +116,13 @@ export class LineItem {
|
||||
@Column({ nullable: true, type: "int" })
|
||||
shipped_quantity: number
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
refundable: number | null
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Currency } from "./currency"
|
||||
import { ProductVariant } from "./product-variant"
|
||||
@@ -55,13 +56,13 @@ export class MoneyAmount {
|
||||
@JoinColumn({ name: "region_id" })
|
||||
region: Region
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Customer } from "./customer"
|
||||
import { NotificationProvider } from "./notification-provider"
|
||||
@@ -42,7 +43,7 @@ export class Notification {
|
||||
@Column()
|
||||
to: string
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
@@ -65,10 +66,10 @@ export class Notification {
|
||||
@JoinColumn({ name: "provider_id" })
|
||||
provider: NotificationProvider
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class Oauth {
|
||||
@@ -35,7 +36,7 @@ export class Oauth {
|
||||
@Column({ nullable: true })
|
||||
uninstall_url: string
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
data: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -15,6 +15,12 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import {
|
||||
resolveDbType,
|
||||
resolveDbGenerationStrategy,
|
||||
DbAwareColumn,
|
||||
} from "../utils/db-aware-column"
|
||||
import { manualAutoIncrement } from "../utils/manual-auto-increment"
|
||||
|
||||
import { Address } from "./address"
|
||||
import { LineItem } from "./line-item"
|
||||
@@ -69,18 +75,22 @@ export class Order {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({ type: "enum", enum: OrderStatus, default: "pending" })
|
||||
@DbAwareColumn({ type: "enum", enum: OrderStatus, default: "pending" })
|
||||
status: OrderStatus
|
||||
|
||||
@Column({ type: "enum", enum: FulfillmentStatus, default: "not_fulfilled" })
|
||||
@DbAwareColumn({
|
||||
type: "enum",
|
||||
enum: FulfillmentStatus,
|
||||
default: "not_fulfilled",
|
||||
})
|
||||
fulfillment_status: FulfillmentStatus
|
||||
|
||||
@Column({ type: "enum", enum: PaymentStatus, default: "not_paid" })
|
||||
@DbAwareColumn({ type: "enum", enum: PaymentStatus, default: "not_paid" })
|
||||
payment_status: PaymentStatus
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
@Generated("increment")
|
||||
@Generated(resolveDbGenerationStrategy("increment"))
|
||||
display_id: number
|
||||
|
||||
@Index()
|
||||
@@ -233,19 +243,19 @@ export class Order {
|
||||
)
|
||||
gift_card_transactions: GiftCardTransaction[]
|
||||
|
||||
@Column({ nullable: true, type: "timestamptz" })
|
||||
@Column({ nullable: true, type: resolveDbType("timestamptz") })
|
||||
canceled_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ type: "boolean", nullable: true})
|
||||
@Column({ type: "boolean", nullable: true })
|
||||
no_notification: Boolean
|
||||
|
||||
@Column({ nullable: true })
|
||||
@@ -263,10 +273,15 @@ export class Order {
|
||||
gift_card_total: number
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
const id = ulid()
|
||||
this.id = `order_${id}`
|
||||
private async beforeInsert() {
|
||||
if (!this.id) {
|
||||
const id = ulid()
|
||||
this.id = `order_${id}`
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === "development" && !this.display_id) {
|
||||
this.display_id = await manualAutoIncrement("order")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Unique,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
import { Cart } from "./cart"
|
||||
|
||||
export enum PaymentSessionStatus {
|
||||
@@ -45,16 +46,16 @@ export class PaymentSession {
|
||||
@Column({ nullable: true })
|
||||
is_selected: boolean
|
||||
|
||||
@Column({ type: "enum", enum: PaymentSessionStatus })
|
||||
@DbAwareColumn({ type: "enum", enum: PaymentSessionStatus })
|
||||
status: string
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Swap } from "./swap"
|
||||
import { Currency } from "./currency"
|
||||
@@ -67,22 +68,22 @@ export class Payment {
|
||||
@Column()
|
||||
provider_id: string
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
captured_at: Date
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
canceled_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
OneToMany,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
import _ from "lodash"
|
||||
|
||||
import { Product } from "./product"
|
||||
@@ -33,16 +34,16 @@ export class ProductCollection {
|
||||
)
|
||||
products: Product[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { ProductOption } from "./product-option"
|
||||
import { ProductVariant } from "./product-variant"
|
||||
@@ -45,16 +46,16 @@ export class ProductOptionValue {
|
||||
@JoinColumn({ name: "variant_id" })
|
||||
variant: ProductVariant
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Product } from "./product"
|
||||
import { ProductOptionValue } from "./product-option-value"
|
||||
@@ -39,16 +40,16 @@ export class ProductOption {
|
||||
@JoinColumn({ name: "product_id" })
|
||||
product: Product
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class ProductTag {
|
||||
@@ -17,16 +18,16 @@ export class ProductTag {
|
||||
@Column()
|
||||
value: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class ProductType {
|
||||
@@ -17,16 +18,16 @@ export class ProductType {
|
||||
@Column()
|
||||
value: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Product } from "./product"
|
||||
import { MoneyAmount } from "./money-amount"
|
||||
@@ -102,16 +103,16 @@ export class ProductVariant {
|
||||
)
|
||||
options: ProductOptionValue[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Image } from "./image"
|
||||
import { ProductCollection } from "./product-collection"
|
||||
@@ -139,16 +140,16 @@ export class Product {
|
||||
@Column({ default: true })
|
||||
discountable: boolean
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Currency } from "./currency"
|
||||
import { Cart } from "./cart"
|
||||
@@ -46,16 +47,16 @@ export class Refund {
|
||||
@Column({ nullable: true })
|
||||
note: string
|
||||
|
||||
@Column({ type: "enum", enum: RefundReason })
|
||||
@DbAwareColumn({ type: "enum", enum: RefundReason })
|
||||
reason: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Currency } from "./currency"
|
||||
import { Country } from "./country"
|
||||
@@ -74,16 +75,16 @@ export class Region {
|
||||
})
|
||||
fulfillment_providers: FulfillmentProvider[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
JoinColumn,
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { ReturnReason } from "./return-reason"
|
||||
import { Return } from "./return"
|
||||
@@ -58,7 +59,7 @@ export class ReturnItem {
|
||||
@Column({ nullable: true })
|
||||
note: string
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class ReturnReason {
|
||||
@@ -25,16 +26,16 @@ export class ReturnReason {
|
||||
@Column({ nullable: true })
|
||||
description: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Order } from "./order"
|
||||
import { Swap } from "./swap"
|
||||
@@ -34,7 +35,11 @@ export class Return {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({ type: "enum", enum: ReturnStatus, default: ReturnStatus.REQUESTED })
|
||||
@DbAwareColumn({
|
||||
type: "enum",
|
||||
enum: ReturnStatus,
|
||||
default: ReturnStatus.REQUESTED,
|
||||
})
|
||||
status: ReturnStatus
|
||||
|
||||
@OneToMany(
|
||||
@@ -84,25 +89,25 @@ export class Return {
|
||||
)
|
||||
shipping_method: ShippingMethod
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
shipping_data: any
|
||||
|
||||
@Column({ type: "int" })
|
||||
refund_amount: number
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
received_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "boolean", nullable: true})
|
||||
@Column({ type: "boolean", nullable: true })
|
||||
no_notification: Boolean
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Index,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { Order } from "./order"
|
||||
@@ -81,7 +82,7 @@ export class ShippingMethod {
|
||||
@Column({ type: "int" })
|
||||
price: number
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
@@ -37,7 +38,7 @@ export class ShippingOptionRequirement {
|
||||
@JoinColumn({ name: "shipping_option_id" })
|
||||
shipping_option: ShippingOption
|
||||
|
||||
@Column({ type: "enum", enum: RequirementType })
|
||||
@DbAwareColumn({ type: "enum", enum: RequirementType })
|
||||
type: RequirementType
|
||||
|
||||
@Column({ type: "int" })
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { ShippingProfile } from "./shipping-profile"
|
||||
import { Region } from "./region"
|
||||
@@ -61,7 +62,7 @@ export class ShippingOption {
|
||||
@JoinColumn({ name: "provider_id" })
|
||||
provider: FulfillmentProvider
|
||||
|
||||
@Column({ type: "enum", enum: ShippingOptionPriceType })
|
||||
@DbAwareColumn({ type: "enum", enum: ShippingOptionPriceType })
|
||||
price_type: ShippingOptionPriceType
|
||||
|
||||
@Column({ type: "int", nullable: true })
|
||||
@@ -80,19 +81,19 @@ export class ShippingOption {
|
||||
)
|
||||
requirements: ShippingOptionRequirement[]
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -5,16 +5,11 @@ import {
|
||||
DeleteDateColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
RelationId,
|
||||
PrimaryColumn,
|
||||
OneToOne,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinColumn,
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
import { Product } from "./product"
|
||||
@@ -33,7 +28,7 @@ export class ShippingProfile {
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@Column({ type: "enum", enum: ShippingProfileType })
|
||||
@DbAwareColumn({ type: "enum", enum: ShippingProfileType })
|
||||
type: ShippingProfileType
|
||||
|
||||
@OneToMany(
|
||||
@@ -48,16 +43,16 @@ export class ShippingProfile {
|
||||
)
|
||||
shipping_options: ShippingOption[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class StagedJob {
|
||||
@@ -24,7 +25,7 @@ export class StagedJob {
|
||||
@Column()
|
||||
event_name: string
|
||||
|
||||
@Column({ type: "jsonb" })
|
||||
@DbAwareColumn({ type: "jsonb" })
|
||||
data: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Currency } from "./currency"
|
||||
|
||||
@@ -53,13 +54,13 @@ export class Store {
|
||||
@Column({ nullable: true })
|
||||
payment_link_template: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Order } from "./order"
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
@@ -49,10 +50,10 @@ export class Swap {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({ type: "enum", enum: FulfillmentStatus })
|
||||
@DbAwareColumn({ type: "enum", enum: FulfillmentStatus })
|
||||
fulfillment_status: FulfillmentStatus
|
||||
|
||||
@Column({ type: "enum", enum: PaymentStatus })
|
||||
@DbAwareColumn({ type: "enum", enum: PaymentStatus })
|
||||
payment_status: PaymentStatus
|
||||
|
||||
@Index()
|
||||
@@ -118,22 +119,22 @@ export class Swap {
|
||||
@JoinColumn({ name: "cart_id" })
|
||||
cart: Cart
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
confirmed_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "boolean", nullable: true})
|
||||
@Column({ type: "boolean", nullable: true })
|
||||
no_notification: Boolean
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
|
||||
@@ -39,16 +40,16 @@ export class TrackingLink {
|
||||
@JoinColumn({ name: "fulfillment_id" })
|
||||
fulfillment: Fulfillment
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
PrimaryColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@@ -31,16 +32,16 @@ export class User {
|
||||
@Column({ nullable: true })
|
||||
api_token: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
|
||||
@@ -13,6 +13,9 @@ describe("LineItemService", () => {
|
||||
})
|
||||
|
||||
const regionService = {
|
||||
withTransaction: function() {
|
||||
return this
|
||||
},
|
||||
retrieve: () => {
|
||||
return {
|
||||
id: IdMap.getId("test-region"),
|
||||
@@ -21,6 +24,9 @@ describe("LineItemService", () => {
|
||||
}
|
||||
|
||||
const productVariantService = {
|
||||
withTransaction: function() {
|
||||
return this
|
||||
},
|
||||
retrieve: query => {
|
||||
if (query === IdMap.getId("test-giftcard")) {
|
||||
return {
|
||||
|
||||
@@ -20,7 +20,10 @@ class EventBusService {
|
||||
case "subscriber":
|
||||
return redisSubscriber
|
||||
default:
|
||||
return new Redis(config.projectConfig.redis_url)
|
||||
if (config.projectConfig.redis_url) {
|
||||
return new Redis(config.projectConfig.redis_url)
|
||||
}
|
||||
return redisClient
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -90,45 +90,50 @@ class LineItemService extends BaseService {
|
||||
}
|
||||
|
||||
async generate(variantId, regionId, quantity, config = {}) {
|
||||
const variant = await this.productVariantService_.retrieve(variantId, {
|
||||
relations: ["product"],
|
||||
})
|
||||
return this.atomicPhase_(async manager => {
|
||||
const variant = await this.productVariantService_
|
||||
.withTransaction(manager)
|
||||
.retrieve(variantId, {
|
||||
relations: ["product"],
|
||||
})
|
||||
|
||||
const region = await this.regionService_.retrieve(regionId)
|
||||
const region = await this.regionService_
|
||||
.withTransaction(manager)
|
||||
.retrieve(regionId)
|
||||
|
||||
let price
|
||||
let shouldMerge = true
|
||||
let price
|
||||
let shouldMerge = true
|
||||
|
||||
if (config.unit_price && typeof config.unit_price !== `undefined`) {
|
||||
// if custom unit_price, we ensure positive values
|
||||
// and we choose to not merge the items
|
||||
shouldMerge = false
|
||||
if (config.unit_price < 0) {
|
||||
price = 0
|
||||
if (config.unit_price && typeof config.unit_price !== `undefined`) {
|
||||
// if custom unit_price, we ensure positive values
|
||||
// and we choose to not merge the items
|
||||
shouldMerge = false
|
||||
if (config.unit_price < 0) {
|
||||
price = 0
|
||||
} else {
|
||||
price = config.unit_price
|
||||
}
|
||||
} else {
|
||||
price = config.unit_price
|
||||
price = await this.productVariantService_
|
||||
.withTransaction(manager)
|
||||
.getRegionPrice(variant.id, region.id)
|
||||
}
|
||||
} else {
|
||||
price = await this.productVariantService_.getRegionPrice(
|
||||
variant.id,
|
||||
region.id
|
||||
)
|
||||
}
|
||||
|
||||
const toCreate = {
|
||||
unit_price: price,
|
||||
title: variant.product.title,
|
||||
description: variant.title,
|
||||
thumbnail: variant.product.thumbnail,
|
||||
variant_id: variant.id,
|
||||
quantity: quantity || 1,
|
||||
allow_discounts: variant.product.discountable,
|
||||
is_giftcard: variant.product.is_giftcard,
|
||||
metadata: config?.metadata || {},
|
||||
should_merge: shouldMerge,
|
||||
}
|
||||
const toCreate = {
|
||||
unit_price: price,
|
||||
title: variant.product.title,
|
||||
description: variant.title,
|
||||
thumbnail: variant.product.thumbnail,
|
||||
variant_id: variant.id,
|
||||
quantity: quantity || 1,
|
||||
allow_discounts: variant.product.discountable,
|
||||
is_giftcard: variant.product.is_giftcard,
|
||||
metadata: config?.metadata || {},
|
||||
should_merge: shouldMerge,
|
||||
}
|
||||
|
||||
return toCreate
|
||||
return toCreate
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import path from "path"
|
||||
import { Column, ColumnOptions, ColumnType } from "typeorm"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
|
||||
const pgSqliteTypeMapping: { [key: string]: ColumnType } = {
|
||||
increment: "rowid",
|
||||
timestamptz: "datetime",
|
||||
jsonb: "simple-json",
|
||||
enum: "text",
|
||||
}
|
||||
|
||||
const pgSqliteGenerationMapping: {
|
||||
[key: string]: "increment" | "uuid" | "rowid"
|
||||
} = {
|
||||
increment: "rowid",
|
||||
}
|
||||
|
||||
let dbType: string
|
||||
export function resolveDbType(pgSqlType: ColumnType): ColumnType {
|
||||
if (!dbType) {
|
||||
const { configModule } = getConfigFile(path.resolve("."), `medusa-config`)
|
||||
dbType = configModule.projectConfig.database_type
|
||||
}
|
||||
|
||||
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
|
||||
return pgSqliteTypeMapping[pgSqlType.toString()]
|
||||
}
|
||||
return pgSqlType
|
||||
}
|
||||
|
||||
export function resolveDbGenerationStrategy(
|
||||
pgSqlType: "increment" | "uuid" | "rowid"
|
||||
): "increment" | "uuid" | "rowid" {
|
||||
if (!dbType) {
|
||||
const { configModule } = getConfigFile(path.resolve("."), `medusa-config`)
|
||||
dbType = configModule.projectConfig.database_type
|
||||
}
|
||||
|
||||
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
|
||||
return pgSqliteGenerationMapping[pgSqlType]
|
||||
}
|
||||
return pgSqlType
|
||||
}
|
||||
|
||||
export function DbAwareColumn(columnOptions: ColumnOptions) {
|
||||
const pre = columnOptions.type
|
||||
if (columnOptions.type) {
|
||||
columnOptions.type = resolveDbType(columnOptions.type)
|
||||
}
|
||||
|
||||
if (pre === "jsonb" && pre !== columnOptions.type) {
|
||||
if ("default" in columnOptions) {
|
||||
columnOptions.default = JSON.stringify(columnOptions.default)
|
||||
}
|
||||
}
|
||||
|
||||
return Column(columnOptions)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import path from "path"
|
||||
import { getConnection } from "typeorm"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
|
||||
export async function manualAutoIncrement(
|
||||
tableName: string
|
||||
): Promise<number | null> {
|
||||
const { configModule } = getConfigFile(path.resolve("."), `medusa-config`)
|
||||
const dbType = configModule.projectConfig.database_type
|
||||
if (dbType === "sqlite") {
|
||||
const connection = getConnection()
|
||||
const [rec] = await connection.query(
|
||||
`SELECT MAX(rowid) as mr FROM "${tableName}"`
|
||||
)
|
||||
|
||||
let mr = 0
|
||||
if (rec && rec.mr) {
|
||||
mr = rec.mr
|
||||
}
|
||||
return mr + 1
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user