@unchainedshop/core-countries 4.0.0-rc.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/db/CountriesCollection.d.ts.map +1 -1
- package/lib/db/CountriesCollection.js +14 -10
- package/lib/db/CountriesCollection.js.map +1 -1
- package/lib/db/CountriesSchema.d.ts +3 -0
- package/lib/db/CountriesSchema.d.ts.map +1 -0
- package/lib/db/CountriesSchema.js +9 -0
- package/lib/db/CountriesSchema.js.map +1 -0
- package/lib/migrations/addMigrations.d.ts +3 -0
- package/lib/migrations/addMigrations.d.ts.map +1 -0
- package/lib/migrations/addMigrations.js +28 -0
- package/lib/migrations/addMigrations.js.map +1 -0
- package/lib/module/configureCountriesModule.d.ts +8 -7
- package/lib/module/configureCountriesModule.d.ts.map +1 -1
- package/lib/module/configureCountriesModule.js +7 -2
- package/lib/module/configureCountriesModule.js.map +1 -1
- package/package.json +3 -3
- package/src/db/CountriesCollection.ts +15 -10
- package/src/module/configureCountriesModule.ts +10 -10
- package/tsconfig.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CountriesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiD,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,eAAO,MAAM,mBAAmB,GAAU,IAAI,OAAO,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"CountriesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiD,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,eAAO,MAAM,mBAAmB,GAAU,IAAI,OAAO,CAAC,EAAE,yCA4BvD,CAAC"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { buildDbIndexes, isDocumentDBCompatModeEnabled } from '@unchainedshop/mongodb';
|
|
2
2
|
export const CountriesCollection = async (db) => {
|
|
3
3
|
const Countries = db.collection('countries');
|
|
4
|
+
if (!isDocumentDBCompatModeEnabled()) {
|
|
5
|
+
await buildDbIndexes(Countries, [
|
|
6
|
+
{
|
|
7
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
8
|
+
options: {
|
|
9
|
+
weights: {
|
|
10
|
+
_id: 8,
|
|
11
|
+
isoCode: 6,
|
|
12
|
+
},
|
|
13
|
+
name: 'countries_fulltext_search',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
4
18
|
await buildDbIndexes(Countries, [
|
|
5
19
|
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
6
20
|
{
|
|
@@ -8,16 +22,6 @@ export const CountriesCollection = async (db) => {
|
|
|
8
22
|
deleted: 1,
|
|
9
23
|
},
|
|
10
24
|
},
|
|
11
|
-
!isDocumentDBCompatModeEnabled() && {
|
|
12
|
-
index: { isoCode: 'text', _id: 'text' },
|
|
13
|
-
options: {
|
|
14
|
-
weights: {
|
|
15
|
-
_id: 8,
|
|
16
|
-
isoCode: 6,
|
|
17
|
-
},
|
|
18
|
-
name: 'countries_fulltext_search',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
25
|
]);
|
|
22
26
|
return Countries;
|
|
23
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CountriesCollection.js","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAGhG,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IAC1D,MAAM,SAAS,GAAG,EAAE,CAAC,UAAU,CAAU,WAAW,CAAC,CAAC;IAEtD,MAAM,cAAc,CAAU,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"CountriesCollection.js","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAGhG,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IAC1D,MAAM,SAAS,GAAG,EAAE,CAAC,UAAU,CAAU,WAAW,CAAC,CAAC;IAEtD,IAAI,CAAC,6BAA6B,EAAE,EAAE,CAAC;QACrC,MAAM,cAAc,CAAU,SAAS,EAAE;YACvC;gBACE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;gBACvC,OAAO,EAAE;oBACP,OAAO,EAAE;wBACP,GAAG,EAAE,CAAC;wBACN,OAAO,EAAE,CAAC;qBACX;oBACD,IAAI,EAAE,2BAA2B;iBAClC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,cAAc,CAAU,SAAS,EAAE;QACvC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QACpD;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC;aACX;SACF;KACF,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountriesSchema.d.ts","sourceRoot":"","sources":["../../src/db/CountriesSchema.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,eAAe,cAQ3B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
+
import SimpleSchema from 'simpl-schema';
|
|
3
|
+
export const CountriesSchema = new SimpleSchema({
|
|
4
|
+
isoCode: { type: String, required: true },
|
|
5
|
+
isActive: Boolean,
|
|
6
|
+
defaultCurrencyCode: String,
|
|
7
|
+
...Schemas.timestampFields,
|
|
8
|
+
}, { requiredByDefault: false });
|
|
9
|
+
//# sourceMappingURL=CountriesSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountriesSchema.js","sourceRoot":"","sources":["../../src/db/CountriesSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,YAAY,CAC7C;IACE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,QAAQ,EAAE,OAAO;IACjB,mBAAmB,EAAE,MAAM;IAC3B,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMigrations.d.ts","sourceRoot":"","sources":["../../src/migrations/addMigrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAI9E,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAAU,EAAE,mBAAmB,CAAC,SAAS,CAAC,QAmC/E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CountriesCollection } from '../db/CountriesCollection.js';
|
|
2
|
+
export default function addMigrations(repository) {
|
|
3
|
+
repository?.register({
|
|
4
|
+
id: 20240712123500,
|
|
5
|
+
name: 'Convert all tags to lower case to make it easy for search',
|
|
6
|
+
up: async () => {
|
|
7
|
+
const Currencies = await repository.db.collection('currencies');
|
|
8
|
+
const Countries = await CountriesCollection(repository.db);
|
|
9
|
+
const allCurrencies = await Currencies.find({}).toArray();
|
|
10
|
+
const allCountries = await Countries.find({}).toArray();
|
|
11
|
+
const currencyMap = allCurrencies.reduce((acc, currency) => {
|
|
12
|
+
acc[currency._id] = currency.isoCode;
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
for (const country of allCountries) {
|
|
16
|
+
await Countries.updateOne({ _id: country._id, defaultCurrencyId: { $exists: true } }, {
|
|
17
|
+
$set: {
|
|
18
|
+
defaultCurrencyCode: currencyMap[country.defaultCurrencyId],
|
|
19
|
+
},
|
|
20
|
+
$unset: {
|
|
21
|
+
defaultCurrencyId: 1,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=addMigrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMigrations.js","sourceRoot":"","sources":["../../src/migrations/addMigrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGnE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAA0C;IAC9E,UAAU,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,2DAA2D;QACjE,EAAE,EAAE,KAAK,IAAI,EAAE;YACb,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,EAAE,CAAC,UAAU,CAAmC,YAAY,CAAC,CAAC;YAClG,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAE3D,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YAC1D,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YAExD,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CACtC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;gBAChB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC;gBACrC,OAAO,GAAG,CAAC;YACb,CAAC,EACD,EAAyB,CAC1B,CAAC;YAEF,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;gBACnC,MAAM,SAAS,CAAC,SAAS,CACvB,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAC1D;oBACE,IAAI,EAAE;wBACJ,mBAAmB,EACjB,WAAW,CAAE,OAAmD,CAAC,iBAAiB,CAAC;qBACtF;oBACD,MAAM,EAAE;wBACN,iBAAiB,EAAE,CAAC;qBACrB;iBACF,CACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mongodb, TimestampFields, ModuleInput } from '@unchainedshop/mongodb';
|
|
2
2
|
import { SortOption } from '@unchainedshop/utils';
|
|
3
3
|
export type Country = {
|
|
4
|
-
_id
|
|
4
|
+
_id: string;
|
|
5
5
|
isoCode: string;
|
|
6
6
|
isActive?: boolean;
|
|
7
7
|
defaultCurrencyCode?: string;
|
|
@@ -13,10 +13,11 @@ export type CountryQuery = mongodb.Filter<Country> & {
|
|
|
13
13
|
export declare const buildFindSelector: ({ includeInactive, queryString, ...rest }: CountryQuery) => mongodb.Filter<Country>;
|
|
14
14
|
export declare const configureCountriesModule: ({ db }: ModuleInput<Record<string, never>>) => Promise<{
|
|
15
15
|
count: (query: CountryQuery) => Promise<number>;
|
|
16
|
-
findCountry: (
|
|
17
|
-
countryId
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
findCountry: (params: {
|
|
17
|
+
countryId: string;
|
|
18
|
+
} | {
|
|
19
|
+
isoCode: string;
|
|
20
|
+
}) => Promise<mongodb.WithId<Country> | null>;
|
|
20
21
|
findCountries: ({ limit, offset, sort, ...query }: CountryQuery & {
|
|
21
22
|
limit?: number;
|
|
22
23
|
offset?: number;
|
|
@@ -25,10 +26,10 @@ export declare const configureCountriesModule: ({ db }: ModuleInput<Record<strin
|
|
|
25
26
|
countryExists: ({ countryId }: {
|
|
26
27
|
countryId: string;
|
|
27
28
|
}) => Promise<boolean>;
|
|
28
|
-
name(country: Country, locale: Intl.Locale): string;
|
|
29
|
+
name(country: Country, locale: Intl.Locale): string | undefined;
|
|
29
30
|
flagEmoji(country: Country): string;
|
|
30
31
|
isBase(country: Country): boolean;
|
|
31
|
-
create: (doc: Country) => Promise<string>;
|
|
32
|
+
create: (doc: Omit<Country, "_id" | "created"> & Pick<Partial<Country>, "_id" | "created">) => Promise<string>;
|
|
32
33
|
update: (countryId: string, doc: Country) => Promise<string>;
|
|
33
34
|
delete: (countryId: string) => Promise<number>;
|
|
34
35
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureCountriesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAiB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIjE,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,
|
|
1
|
+
{"version":3,"file":"configureCountriesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAiB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIjE,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,GAAG,eAAe,CAAC;AAEpB,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG;IACnD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF,eAAO,MAAM,iBAAiB,GAAI,2CAI/B,YAAY,4BAQd,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAU,QAAQ,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;mBAMhE,YAAY,KAAG,OAAO,CAAC,MAAM,CAAC;0BAKvB;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;uDAclE,YAAY,GAAG;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;KACrB,YACS,OAAO,CAAC,WAAW,KAC5B,OAAO,CAAC,OAAO,EAAE,CAAC;mCAWgB;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,OAAO,CAAC;kBAU/D,OAAO,UAAU,IAAI,CAAC,MAAM;uBAIvB,OAAO;oBAOV,OAAO;kBAKhB,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;wBAczD,MAAM,OAAO,OAAO;wBAWpB,MAAM;EAanC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC"}
|
|
@@ -23,8 +23,13 @@ export const configureCountriesModule = async ({ db }) => {
|
|
|
23
23
|
const countryCount = await Countries.countDocuments(buildFindSelector(query));
|
|
24
24
|
return countryCount;
|
|
25
25
|
},
|
|
26
|
-
findCountry: async (
|
|
27
|
-
|
|
26
|
+
findCountry: async (params) => {
|
|
27
|
+
if ('countryId' in params) {
|
|
28
|
+
return Countries.findOne(generateDbFilterById(params.countryId));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return Countries.findOne({ isoCode: params.isoCode });
|
|
32
|
+
}
|
|
28
33
|
},
|
|
29
34
|
findCountries: async ({ limit, offset, sort, ...query }, options) => {
|
|
30
35
|
const defaultSort = [{ key: 'created', value: SortDirection.ASC }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureCountriesModule.js","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAc,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAcnE,MAAM,cAAc,GAAa,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,eAAe,GAAG,KAAK,EACvB,WAAW,GAAG,EAAE,EAChB,GAAG,IAAI,EACM,EAAE,EAAE;IACjB,MAAM,QAAQ,GAA4B,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACrE,IAAI,CAAC,eAAe;QAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC/C,IAAI,WAAW,EAAE,CAAC;QAChB,0BAA0B,EAAE,CAAC;QAC7B,QAAQ,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAC5C,CAAC;I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shop/core-countries",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"main": "lib/countries-index.js",
|
|
5
5
|
"types": "lib/countries-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^4.0.0
|
|
35
|
-
"@unchainedshop/utils": "^4.0.0
|
|
34
|
+
"@unchainedshop/events": "^4.0.0",
|
|
35
|
+
"@unchainedshop/utils": "^4.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^24.0.13",
|
|
@@ -4,6 +4,21 @@ import { Country } from '../countries-index.js';
|
|
|
4
4
|
export const CountriesCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const Countries = db.collection<Country>('countries');
|
|
6
6
|
|
|
7
|
+
if (!isDocumentDBCompatModeEnabled()) {
|
|
8
|
+
await buildDbIndexes<Country>(Countries, [
|
|
9
|
+
{
|
|
10
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
11
|
+
options: {
|
|
12
|
+
weights: {
|
|
13
|
+
_id: 8,
|
|
14
|
+
isoCode: 6,
|
|
15
|
+
},
|
|
16
|
+
name: 'countries_fulltext_search',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
await buildDbIndexes<Country>(Countries, [
|
|
8
23
|
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
9
24
|
{
|
|
@@ -11,16 +26,6 @@ export const CountriesCollection = async (db: mongodb.Db) => {
|
|
|
11
26
|
deleted: 1,
|
|
12
27
|
},
|
|
13
28
|
},
|
|
14
|
-
!isDocumentDBCompatModeEnabled() && {
|
|
15
|
-
index: { isoCode: 'text', _id: 'text' },
|
|
16
|
-
options: {
|
|
17
|
-
weights: {
|
|
18
|
-
_id: 8,
|
|
19
|
-
isoCode: 6,
|
|
20
|
-
},
|
|
21
|
-
name: 'countries_fulltext_search',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
29
|
]);
|
|
25
30
|
|
|
26
31
|
return Countries;
|
|
@@ -11,7 +11,7 @@ import { systemLocale } from '@unchainedshop/utils';
|
|
|
11
11
|
import { CountriesCollection } from '../db/CountriesCollection.js';
|
|
12
12
|
|
|
13
13
|
export type Country = {
|
|
14
|
-
_id
|
|
14
|
+
_id: string;
|
|
15
15
|
isoCode: string;
|
|
16
16
|
isActive?: boolean;
|
|
17
17
|
defaultCurrencyCode?: string;
|
|
@@ -49,14 +49,12 @@ export const configureCountriesModule = async ({ db }: ModuleInput<Record<string
|
|
|
49
49
|
return countryCount;
|
|
50
50
|
},
|
|
51
51
|
|
|
52
|
-
findCountry: async ({
|
|
53
|
-
countryId
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}): Promise<Country> => {
|
|
59
|
-
return Countries.findOne(countryId ? generateDbFilterById(countryId) : { isoCode });
|
|
52
|
+
findCountry: async (params: { countryId: string } | { isoCode: string }) => {
|
|
53
|
+
if ('countryId' in params) {
|
|
54
|
+
return Countries.findOne(generateDbFilterById(params.countryId));
|
|
55
|
+
} else {
|
|
56
|
+
return Countries.findOne({ isoCode: params.isoCode });
|
|
57
|
+
}
|
|
60
58
|
},
|
|
61
59
|
|
|
62
60
|
findCountries: async (
|
|
@@ -107,7 +105,9 @@ export const configureCountriesModule = async ({ db }: ModuleInput<Record<string
|
|
|
107
105
|
return country.isoCode === systemLocale.region;
|
|
108
106
|
},
|
|
109
107
|
|
|
110
|
-
create: async (
|
|
108
|
+
create: async (
|
|
109
|
+
doc: Omit<Country, '_id' | 'created'> & Pick<Partial<Country>, '_id' | 'created'>,
|
|
110
|
+
) => {
|
|
111
111
|
await Countries.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
112
112
|
const { insertedId: countryId } = await Countries.insertOne({
|
|
113
113
|
_id: generateDbObjectId(),
|