@unchainedshop/core-countries 3.1.13 → 4.0.0-rc.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CountriesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,eAAO,MAAM,mBAAmB,GAAU,IAAI,OAAO,CAAC,EAAE,yCAuBvD,CAAC"}
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,yCAuBvD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { buildDbIndexes } from '@unchainedshop/mongodb';
1
+ import { buildDbIndexes, isDocumentDBCompatModeEnabled } from '@unchainedshop/mongodb';
2
2
  export const CountriesCollection = async (db) => {
3
3
  const Countries = db.collection('countries');
4
4
  await buildDbIndexes(Countries, [
@@ -8,7 +8,7 @@ export const CountriesCollection = async (db) => {
8
8
  deleted: 1,
9
9
  },
10
10
  },
11
- {
11
+ !isDocumentDBCompatModeEnabled() && {
12
12
  index: { isoCode: 'text', _id: 'text' },
13
13
  options: {
14
14
  weights: {
@@ -1 +1 @@
1
- {"version":3,"file":"CountriesCollection.js","sourceRoot":"","sources":["../../src/db/CountriesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGjE,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;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;QACD;YACE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;YACvC,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC;oBACN,OAAO,EAAE,CAAC;iBACX;gBACD,IAAI,EAAE,2BAA2B;aAClC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
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;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;QACD,CAAC,6BAA6B,EAAE,IAAI;YAClC,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;YACvC,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC;oBACN,OAAO,EAAE,CAAC;iBACX;gBACD,IAAI,EAAE,2BAA2B;aAClC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -6,30 +6,26 @@ export type Country = {
6
6
  isActive?: boolean;
7
7
  defaultCurrencyCode?: string;
8
8
  } & TimestampFields;
9
- export type CountryQuery = {
9
+ export type CountryQuery = mongodb.Filter<Country> & {
10
10
  includeInactive?: boolean;
11
11
  queryString?: string;
12
12
  };
13
- export declare const buildFindSelector: ({ includeInactive, queryString }: CountryQuery) => {
14
- isActive?: true;
15
- $text?: any;
16
- deleted?: Date;
17
- };
18
- export declare const configureCountriesModule: ({ db, migrationRepository, }: ModuleInput<Record<string, never>>) => Promise<{
13
+ export declare const buildFindSelector: ({ includeInactive, queryString, ...rest }: CountryQuery) => mongodb.Filter<Country>;
14
+ export declare const configureCountriesModule: ({ db }: ModuleInput<Record<string, never>>) => Promise<{
19
15
  count: (query: CountryQuery) => Promise<number>;
20
16
  findCountry: ({ countryId, isoCode, }: {
21
17
  countryId?: string;
22
18
  isoCode?: string;
23
19
  }) => Promise<Country>;
24
- findCountries: ({ limit, offset, sort, includeInactive, queryString, }: CountryQuery & {
20
+ findCountries: ({ limit, offset, sort, ...query }: CountryQuery & {
25
21
  limit?: number;
26
22
  offset?: number;
27
- sort?: Array<SortOption>;
28
- }, options?: mongodb.FindOptions) => Promise<Array<Country>>;
23
+ sort?: SortOption[];
24
+ }, options?: mongodb.FindOptions) => Promise<Country[]>;
29
25
  countryExists: ({ countryId }: {
30
26
  countryId: string;
31
27
  }) => Promise<boolean>;
32
- name(country: Country, language: string): string;
28
+ name(country: Country, locale: Intl.Locale): string;
33
29
  flagEmoji(country: Country): string;
34
30
  isBase(country: Country): boolean;
35
31
  create: (doc: Country) => Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"configureCountriesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,wBAAw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;wBAaD,MAAM,OAAO,OAAO;wBAWpB,MAAM;EAanC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC"}
@@ -1,22 +1,22 @@
1
+ import { assertDocumentDBCompatMode, } from '@unchainedshop/mongodb';
1
2
  import { emit, registerEvents } from '@unchainedshop/events';
2
3
  import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
3
4
  import { SortDirection } from '@unchainedshop/utils';
4
5
  import { systemLocale } from '@unchainedshop/utils';
5
6
  import { CountriesCollection } from '../db/CountriesCollection.js';
6
- import addMigrations from '../migrations/addMigrations.js';
7
7
  const COUNTRY_EVENTS = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
8
- export const buildFindSelector = ({ includeInactive = false, queryString = '' }) => {
9
- const selector = { deleted: null };
8
+ export const buildFindSelector = ({ includeInactive = false, queryString = '', ...rest }) => {
9
+ const selector = { ...rest, deleted: null };
10
10
  if (!includeInactive)
11
11
  selector.isActive = true;
12
- if (queryString)
12
+ if (queryString) {
13
+ assertDocumentDBCompatMode();
13
14
  selector.$text = { $search: queryString };
15
+ }
14
16
  return selector;
15
17
  };
16
- export const configureCountriesModule = async ({ db, migrationRepository, }) => {
18
+ export const configureCountriesModule = async ({ db }) => {
17
19
  registerEvents(COUNTRY_EVENTS);
18
- // Migration
19
- addMigrations(migrationRepository);
20
20
  const Countries = await CountriesCollection(db);
21
21
  return {
22
22
  count: async (query) => {
@@ -26,9 +26,9 @@ export const configureCountriesModule = async ({ db, migrationRepository, }) =>
26
26
  findCountry: async ({ countryId, isoCode, }) => {
27
27
  return Countries.findOne(countryId ? generateDbFilterById(countryId) : { isoCode });
28
28
  },
29
- findCountries: async ({ limit, offset, sort, includeInactive, queryString, }, options) => {
29
+ findCountries: async ({ limit, offset, sort, ...query }, options) => {
30
30
  const defaultSort = [{ key: 'created', value: SortDirection.ASC }];
31
- const countries = Countries.find(buildFindSelector({ includeInactive, queryString }), {
31
+ const countries = Countries.find(buildFindSelector(query), {
32
32
  skip: offset,
33
33
  limit,
34
34
  sort: buildSortOptions(sort || defaultSort),
@@ -42,8 +42,8 @@ export const configureCountriesModule = async ({ db, migrationRepository, }) =>
42
42
  });
43
43
  return !!countryCount;
44
44
  },
45
- name(country, language) {
46
- return new Intl.DisplayNames([language], { type: 'region', fallback: 'code' }).of(country.isoCode);
45
+ name(country, locale) {
46
+ return new Intl.DisplayNames([locale], { type: 'region', fallback: 'code' }).of(country.isoCode);
47
47
  },
48
48
  flagEmoji(country) {
49
49
  const letterToLetterEmoji = (letter) => {
@@ -1 +1 @@
1
- {"version":3,"file":"configureCountriesModule.js","sourceRoot":"","sources":["../../src/module/configureCountriesModule.ts"],"names":[],"mappings":"AACA,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,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAc3D,MAAM,cAAc,GAAa,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,eAAe,GAAG,KAAK,EAAE,WAAW,GAAG,EAAE,EAAgB,EAAE,EAAE;IAC/F,MAAM,QAAQ,GAAqD,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACrF,IAAI,CAAC,eAAe;QAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC/C,IAAI,WAAW;QAAE,QAAQ,CAAC,KAAK,GAAG,EAAE,OAA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AM,SAAS,CAAC,SAAS,CAAC;gBAC1D,GAAG,EAAE,kBAAkB,EAAE;gBACzB,OAAO,EAAE,IAAI,IAAI,EAAE;gBACnB,GAAG,GAAG;gBACN,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;gBAClC,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,SAAiB,EAAE,GAAY,EAAE,EAAE;YAChD,MAAM,SAAS,CAAC,SAAS,CAAC,oBAAoB,CAAC,SAAS,CAAC,EAAE;gBACzD,IAAI,EAAE;oBACJ,OAAO,EAAE,IAAI,IAAI,EAAE;oBACnB,GAAG,GAAG;iBACP;aACF,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,SAAiB,EAAE,EAAE;YAClC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,MAAM,SAAS,CAAC,SAAS,CAC/D,oBAAoB,CAAC,SAAS,CAAC,EAC/B;gBACE,IAAI,EAAE;oBACJ,OAAO,EAAE,IAAI,IAAI,EAAE;iBACpB;aACF,CACF,CAAC;YACF,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,YAAY,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
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;AAC7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SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,SAAiB,EAAE,EAAE;YAClC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,MAAM,SAAS,CAAC,SAAS,CAC/D,oBAAoB,CAAC,SAAS,CAAC,EAC/B;gBACE,IAAI,EAAE;oBACJ,OAAO,EAAE,IAAI,IAAI,EAAE;iBACpB;aACF,CACF,CAAC;YACF,MAAM,IAAI,CAAC,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;YAC5C,OAAO,YAAY,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-countries",
3
- "version": "3.1.13",
3
+ "version": "4.0.0-rc.10",
4
4
  "main": "lib/countries-index.js",
5
5
  "types": "lib/countries-index.d.ts",
6
6
  "type": "module",
@@ -31,11 +31,11 @@
31
31
  },
32
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
33
  "dependencies": {
34
- "@unchainedshop/events": "^3.1.13",
35
- "@unchainedshop/utils": "^3.1.13"
34
+ "@unchainedshop/events": "^4.0.0-rc.4",
35
+ "@unchainedshop/utils": "^4.0.0-rc.4"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "^24.0.4",
38
+ "@types/node": "^24.0.13",
39
39
  "tsx": "^4.20.3",
40
40
  "typescript": "^5.8.3"
41
41
  }
@@ -1,4 +1,4 @@
1
- import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
1
+ import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled } from '@unchainedshop/mongodb';
2
2
  import { Country } from '../countries-index.js';
3
3
 
4
4
  export const CountriesCollection = async (db: mongodb.Db) => {
@@ -11,7 +11,7 @@ export const CountriesCollection = async (db: mongodb.Db) => {
11
11
  deleted: 1,
12
12
  },
13
13
  },
14
- {
14
+ !isDocumentDBCompatModeEnabled() && {
15
15
  index: { isoCode: 'text', _id: 'text' },
16
16
  options: {
17
17
  weights: {
@@ -1,10 +1,14 @@
1
- import { mongodb, TimestampFields, ModuleInput } from '@unchainedshop/mongodb';
1
+ import {
2
+ mongodb,
3
+ TimestampFields,
4
+ ModuleInput,
5
+ assertDocumentDBCompatMode,
6
+ } from '@unchainedshop/mongodb';
2
7
  import { emit, registerEvents } from '@unchainedshop/events';
3
8
  import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
4
9
  import { SortDirection, SortOption } from '@unchainedshop/utils';
5
10
  import { systemLocale } from '@unchainedshop/utils';
6
11
  import { CountriesCollection } from '../db/CountriesCollection.js';
7
- import addMigrations from '../migrations/addMigrations.js';
8
12
 
9
13
  export type Country = {
10
14
  _id?: string;
@@ -13,29 +17,30 @@ export type Country = {
13
17
  defaultCurrencyCode?: string;
14
18
  } & TimestampFields;
15
19
 
16
- export type CountryQuery = {
20
+ export type CountryQuery = mongodb.Filter<Country> & {
17
21
  includeInactive?: boolean;
18
22
  queryString?: string;
19
23
  };
20
24
 
21
25
  const COUNTRY_EVENTS: string[] = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
22
26
 
23
- export const buildFindSelector = ({ includeInactive = false, queryString = '' }: CountryQuery) => {
24
- const selector: { isActive?: true; $text?: any; deleted?: Date } = { deleted: null };
27
+ export const buildFindSelector = ({
28
+ includeInactive = false,
29
+ queryString = '',
30
+ ...rest
31
+ }: CountryQuery) => {
32
+ const selector: mongodb.Filter<Country> = { ...rest, deleted: null };
25
33
  if (!includeInactive) selector.isActive = true;
26
- if (queryString) selector.$text = { $search: queryString };
34
+ if (queryString) {
35
+ assertDocumentDBCompatMode();
36
+ selector.$text = { $search: queryString };
37
+ }
27
38
  return selector;
28
39
  };
29
40
 
30
- export const configureCountriesModule = async ({
31
- db,
32
- migrationRepository,
33
- }: ModuleInput<Record<string, never>>) => {
41
+ export const configureCountriesModule = async ({ db }: ModuleInput<Record<string, never>>) => {
34
42
  registerEvents(COUNTRY_EVENTS);
35
43
 
36
- // Migration
37
- addMigrations(migrationRepository);
38
-
39
44
  const Countries = await CountriesCollection(db);
40
45
 
41
46
  return {
@@ -59,17 +64,16 @@ export const configureCountriesModule = async ({
59
64
  limit,
60
65
  offset,
61
66
  sort,
62
- includeInactive,
63
- queryString,
67
+ ...query
64
68
  }: CountryQuery & {
65
69
  limit?: number;
66
70
  offset?: number;
67
- sort?: Array<SortOption>;
71
+ sort?: SortOption[];
68
72
  },
69
73
  options?: mongodb.FindOptions,
70
- ): Promise<Array<Country>> => {
74
+ ): Promise<Country[]> => {
71
75
  const defaultSort = [{ key: 'created', value: SortDirection.ASC }] as SortOption[];
72
- const countries = Countries.find(buildFindSelector({ includeInactive, queryString }), {
76
+ const countries = Countries.find(buildFindSelector(query), {
73
77
  skip: offset,
74
78
  limit,
75
79
  sort: buildSortOptions(sort || defaultSort),
@@ -88,8 +92,8 @@ export const configureCountriesModule = async ({
88
92
  return !!countryCount;
89
93
  },
90
94
 
91
- name(country: Country, language: string) {
92
- return new Intl.DisplayNames([language], { type: 'region', fallback: 'code' }).of(country.isoCode);
95
+ name(country: Country, locale: Intl.Locale) {
96
+ return new Intl.DisplayNames([locale], { type: 'region', fallback: 'code' }).of(country.isoCode);
93
97
  },
94
98
 
95
99
  flagEmoji(country: Country) {
@@ -1,3 +0,0 @@
1
- import SimpleSchema from 'simpl-schema';
2
- export declare const CountriesSchema: SimpleSchema;
3
- //# sourceMappingURL=CountriesSchema.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- import { MigrationRepository } from '@unchainedshop/mongodb';
2
- export default function addMigrations(repository: MigrationRepository): void;
3
- //# sourceMappingURL=addMigrations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addMigrations.d.ts","sourceRoot":"","sources":["../../src/migrations/addMigrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAAU,EAAE,mBAAmB,QAmCpE"}
@@ -1,28 +0,0 @@
1
- import { CountriesCollection } from '../db/CountriesCollection.js';
2
- export default function addMigrations(repository) {
3
- repository?.register({
4
- id: 20241220123500,
5
- name: 'Remove defaultCurrencyId from countries and add defaultCurrencyCode',
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
@@ -1 +0,0 @@
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,UAA+B;IACnE,UAAU,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,qEAAqE;QAC3E,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,40 +0,0 @@
1
- import { MigrationRepository } from '@unchainedshop/mongodb';
2
- import { CountriesCollection } from '../db/CountriesCollection.js';
3
- import { Country } from '../countries-index.js';
4
-
5
- export default function addMigrations(repository: MigrationRepository) {
6
- repository?.register({
7
- id: 20241220123500,
8
- name: 'Remove defaultCurrencyId from countries and add defaultCurrencyCode',
9
- up: async () => {
10
- const Currencies = await repository.db.collection<{ _id: string; isoCode: string }>('currencies');
11
- const Countries = await CountriesCollection(repository.db);
12
-
13
- const allCurrencies = await Currencies.find({}).toArray();
14
- const allCountries = await Countries.find({}).toArray();
15
-
16
- const currencyMap = allCurrencies.reduce(
17
- (acc, currency) => {
18
- acc[currency._id] = currency.isoCode;
19
- return acc;
20
- },
21
- {} as Record<string, any>,
22
- );
23
-
24
- for (const country of allCountries) {
25
- await Countries.updateOne(
26
- { _id: country._id, defaultCurrencyId: { $exists: true } },
27
- {
28
- $set: {
29
- defaultCurrencyCode:
30
- currencyMap[(country as Country & { defaultCurrencyId: string }).defaultCurrencyId],
31
- },
32
- $unset: {
33
- defaultCurrencyId: 1,
34
- },
35
- },
36
- );
37
- }
38
- },
39
- });
40
- }