feat(medusa): Migrate utils to TS (#1415)
This commit is contained in:
committed by
GitHub
parent
247ad6dc6d
commit
d98cd85d23
@@ -326,8 +326,10 @@ class RegionService extends BaseService {
|
||||
)
|
||||
|
||||
const countryCode = code.toUpperCase()
|
||||
const validCountry = countries.find((c) => c.alpha2 === countryCode)
|
||||
if (!validCountry) {
|
||||
const isCountryExists = countries.some(
|
||||
(country) => country.alpha2 === countryCode
|
||||
)
|
||||
if (!isCountryExists) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"Invalid country code"
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
export const countries = [
|
||||
export type Country = {
|
||||
alpha2: string
|
||||
name: string
|
||||
alpha3: string
|
||||
numeric: string
|
||||
}
|
||||
|
||||
export const countries: Country[] = [
|
||||
{ alpha2: "AF", name: "Afghanistan", alpha3: "AFG", numeric: "004" },
|
||||
{ alpha2: "AL", name: "Albania", alpha3: "ALB", numeric: "008" },
|
||||
{ alpha2: "DZ", name: "Algeria", alpha3: "DZA", numeric: "012" },
|
||||
@@ -1,20 +1,20 @@
|
||||
import path from "path"
|
||||
import { parse } from "path"
|
||||
|
||||
/**
|
||||
* Formats a filename into the correct container resolution name.
|
||||
* Names are camelCase formatted and namespaced by the folder i.e:
|
||||
* models/example-person -> examplePersonModel
|
||||
* @param {string} fn - the full path of the file
|
||||
* @return {string} the formatted name
|
||||
* @param path - the full path of the file
|
||||
* @return the formatted name
|
||||
*/
|
||||
function formatRegistrationName(fn) {
|
||||
const parsed = path.parse(fn)
|
||||
const parsedDir = path.parse(parsed.dir)
|
||||
function formatRegistrationName(path: string): string {
|
||||
const parsed = parse(path)
|
||||
const parsedDir = parse(parsed.dir)
|
||||
|
||||
const rawname = parsed.name
|
||||
let namespace = parsedDir.name
|
||||
if (namespace.startsWith("__")) {
|
||||
const parsedCoreDir = path.parse(parsedDir.dir)
|
||||
const parsedCoreDir = parse(parsedDir.dir)
|
||||
namespace = parsedCoreDir.name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user