feat: Typescript for API layer (#817)

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com>
Co-authored-by: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com>
Co-authored-by: Philip Korsholm <philip.korsholm@hotmail.com>
Co-authored-by: Sebastian Rindom <seb@medusa-commerce.com>
This commit is contained in:
Oliver Windall Juhl
2021-11-18 15:19:17 +01:00
committed by GitHub
co-authored by Philip Korsholm Zakaria El Asri Kasper Fabricius Kristensen Philip Korsholm Sebastian Rindom
parent 55e200bf68
commit 373532ecbc
413 changed files with 20957 additions and 10349 deletions
+11 -5
View File
@@ -1,6 +1,6 @@
import { getConfigFile } from "medusa-core-utils"
import path from "path"
import { Column, ColumnOptions, ColumnType } from "typeorm"
import { getConfigFile } from "medusa-core-utils"
const pgSqliteTypeMapping: { [key: string]: ColumnType } = {
increment: "rowid",
@@ -19,7 +19,10 @@ let dbType: string
export function resolveDbType(pgSqlType: ColumnType): ColumnType {
if (!dbType) {
try {
const { configModule } = getConfigFile(path.resolve("."), `medusa-config`)
const { configModule } = getConfigFile(
path.resolve("."),
`medusa-config`
) as any
dbType = configModule.projectConfig.database_type
} catch (error) {
// Default to Postgres to allow for e.g. migrations to run
@@ -27,7 +30,7 @@ export function resolveDbType(pgSqlType: ColumnType): ColumnType {
}
}
if (dbType === "sqlite" && pgSqlType in pgSqliteTypeMapping) {
if (dbType === "sqlite" && (pgSqlType as string) in pgSqliteTypeMapping) {
return pgSqliteTypeMapping[pgSqlType.toString()]
}
return pgSqlType
@@ -38,7 +41,10 @@ export function resolveDbGenerationStrategy(
): "increment" | "uuid" | "rowid" {
if (!dbType) {
try {
const { configModule } = getConfigFile(path.resolve("."), `medusa-config`)
const { configModule } = getConfigFile(
path.resolve("."),
`medusa-config`
) as any
dbType = configModule.projectConfig.database_type
} catch (error) {
// Default to Postgres to allow for e.g. migrations to run
@@ -52,7 +58,7 @@ export function resolveDbGenerationStrategy(
return pgSqlType
}
export function DbAwareColumn(columnOptions: ColumnOptions) {
export function DbAwareColumn(columnOptions: ColumnOptions): PropertyDecorator {
const pre = columnOptions.type
if (columnOptions.type) {
columnOptions.type = resolveDbType(columnOptions.type)