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