@things-factory/geography 5.0.14 → 6.0.0-alpha.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.
Files changed (44) hide show
  1. package/dist-server/service/geo-area/geo-area-mutation.js +1 -1
  2. package/dist-server/service/geo-area/geo-area-mutation.js.map +1 -1
  3. package/dist-server/service/geo-area/geo-area-query.js +47 -9
  4. package/dist-server/service/geo-area/geo-area-query.js.map +1 -1
  5. package/dist-server/service/geo-area/geo-area.js +3 -4
  6. package/dist-server/service/geo-area/geo-area.js.map +1 -1
  7. package/dist-server/service/geo-city/geo-city-mutation.js +1 -1
  8. package/dist-server/service/geo-city/geo-city-mutation.js.map +1 -1
  9. package/dist-server/service/geo-city/geo-city-query.js +8 -10
  10. package/dist-server/service/geo-city/geo-city-query.js.map +1 -1
  11. package/dist-server/service/geo-city/geo-city.js +3 -4
  12. package/dist-server/service/geo-city/geo-city.js.map +1 -1
  13. package/dist-server/service/geo-continent/geo-continent-mutation.js +1 -1
  14. package/dist-server/service/geo-continent/geo-continent-mutation.js.map +1 -1
  15. package/dist-server/service/geo-continent/geo-continent-query.js +6 -8
  16. package/dist-server/service/geo-continent/geo-continent-query.js.map +1 -1
  17. package/dist-server/service/geo-continent/geo-continent.js +2 -3
  18. package/dist-server/service/geo-continent/geo-continent.js.map +1 -1
  19. package/dist-server/service/geo-country/geo-country-mutation.js +1 -1
  20. package/dist-server/service/geo-country/geo-country-mutation.js.map +1 -1
  21. package/dist-server/service/geo-country/geo-country-query.js +18 -9
  22. package/dist-server/service/geo-country/geo-country-query.js.map +1 -1
  23. package/dist-server/service/geo-country/geo-country.js +2 -3
  24. package/dist-server/service/geo-country/geo-country.js.map +1 -1
  25. package/dist-server/service/geo-state/geo-state-mutation.js +1 -1
  26. package/dist-server/service/geo-state/geo-state-mutation.js.map +1 -1
  27. package/dist-server/service/geo-state/geo-state-query.js +7 -9
  28. package/dist-server/service/geo-state/geo-state-query.js.map +1 -1
  29. package/dist-server/service/geo-state/geo-state.js +2 -3
  30. package/dist-server/service/geo-state/geo-state.js.map +1 -1
  31. package/dist-server/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +5 -5
  33. package/server/service/geo-area/geo-area-mutation.ts +11 -6
  34. package/server/service/geo-area/geo-area-query.ts +42 -8
  35. package/server/service/geo-area/geo-area.ts +1 -1
  36. package/server/service/geo-city/geo-city-mutation.ts +14 -6
  37. package/server/service/geo-city/geo-city-query.ts +10 -9
  38. package/server/service/geo-city/geo-city.ts +1 -1
  39. package/server/service/geo-continent/geo-continent-mutation.ts +10 -6
  40. package/server/service/geo-continent/geo-continent-query.ts +8 -7
  41. package/server/service/geo-country/geo-country-mutation.ts +13 -6
  42. package/server/service/geo-country/geo-country-query.ts +16 -8
  43. package/server/service/geo-state/geo-state-mutation.ts +10 -6
  44. package/server/service/geo-state/geo-state-query.ts +9 -8
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@things-factory/geography",
3
- "version": "5.0.14",
3
+ "version": "6.0.0-alpha.0",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
7
7
  "license": "MIT",
8
- "author": "heartyoh",
8
+ "author": "heartyoh <heartyoh@hatiolab.com>",
9
9
  "description": "A module to manage master data for continents, countries, state, city, area, postal code and coordinate",
10
10
  "publishConfig": {
11
11
  "access": "public",
@@ -24,8 +24,8 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/auth-base": "^5.0.14",
28
- "@things-factory/shell": "^5.0.14"
27
+ "@things-factory/auth-base": "^6.0.0-alpha.0",
28
+ "@things-factory/shell": "^6.0.0-alpha.0"
29
29
  },
30
- "gitHead": "9ceaa39746fcf42953e429fab2001353cd821ded"
30
+ "gitHead": "e5b9823ab3ebc5d6ae5bcb4b5aa60c1306e4dd7e"
31
31
  }
@@ -1,5 +1,6 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
2
  import { In } from 'typeorm'
3
+
3
4
  import { GeoArea } from './geo-area'
4
5
  import { GeoAreaPatch, NewGeoArea } from './geo-area-type'
5
6
 
@@ -7,7 +8,7 @@ import { GeoAreaPatch, NewGeoArea } from './geo-area-type'
7
8
  export class GeoAreaMutation {
8
9
  @Directive('@transaction')
9
10
  @Mutation(returns => GeoArea, { description: 'To create new GeoArea' })
10
- async createGeoArea(@Arg('geoArea') geoArea: NewGeoArea, @Ctx() context: any): Promise<GeoArea> {
11
+ async createGeoArea(@Arg('geoArea') geoArea: NewGeoArea, @Ctx() context: ResolverContext): Promise<GeoArea> {
11
12
  const { user, tx } = context.state
12
13
 
13
14
  return await tx.getRepository(GeoArea).save({
@@ -19,7 +20,11 @@ export class GeoAreaMutation {
19
20
 
20
21
  @Directive('@transaction')
21
22
  @Mutation(returns => GeoArea, { description: 'To modify GeoArea information' })
22
- async updateGeoArea(@Arg('id') id: string, @Arg('patch') patch: GeoAreaPatch, @Ctx() context: any): Promise<GeoArea> {
23
+ async updateGeoArea(
24
+ @Arg('id') id: string,
25
+ @Arg('patch') patch: GeoAreaPatch,
26
+ @Ctx() context: ResolverContext
27
+ ): Promise<GeoArea> {
23
28
  const { user, tx } = context.state
24
29
 
25
30
  const repository = tx.getRepository(GeoArea)
@@ -38,7 +43,7 @@ export class GeoAreaMutation {
38
43
  @Mutation(returns => [GeoArea], { description: "To modify multiple GeoAreas' information" })
39
44
  async updateMultipleGeoArea(
40
45
  @Arg('patches', type => [GeoAreaPatch]) patches: GeoAreaPatch[],
41
- @Ctx() context: any
46
+ @Ctx() context: ResolverContext
42
47
  ): Promise<GeoArea[]> {
43
48
  const { user, tx } = context.state
44
49
 
@@ -64,7 +69,7 @@ export class GeoAreaMutation {
64
69
  if (_updateRecords.length > 0) {
65
70
  for (let i = 0; i < _updateRecords.length; i++) {
66
71
  const newRecord = _updateRecords[i]
67
- const geoArea = await geoAreaRepo.findOne(newRecord.id)
72
+ const geoArea = await geoAreaRepo.findOneBy({ id: newRecord.id })
68
73
 
69
74
  const result = await geoAreaRepo.save({
70
75
  ...geoArea,
@@ -81,7 +86,7 @@ export class GeoAreaMutation {
81
86
 
82
87
  @Directive('@transaction')
83
88
  @Mutation(returns => Boolean, { description: 'To delete GeoArea' })
84
- async deleteGeoArea(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
89
+ async deleteGeoArea(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
85
90
  const { tx } = context.state
86
91
 
87
92
  await tx.getRepository(GeoArea).delete({ id })
@@ -90,7 +95,7 @@ export class GeoAreaMutation {
90
95
 
91
96
  @Directive('@transaction')
92
97
  @Mutation(returns => Boolean, { description: 'To delete multiple geoAreas' })
93
- async deleteGeoAreas(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
98
+ async deleteGeoAreas(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
94
99
  const { domain, tx } = context.state
95
100
 
96
101
  await tx.getRepository(GeoArea).delete({
@@ -1,7 +1,8 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { convertListParams, ListParam } from '@things-factory/shell'
3
1
  import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
4
- import { getRepository } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
5
+
5
6
  import { GeoCity } from '../geo-city/geo-city'
6
7
  import { GeoArea } from './geo-area'
7
8
  import { GeoAreaList } from './geo-area-type'
@@ -9,32 +10,65 @@ import { GeoAreaList } from './geo-area-type'
9
10
  @Resolver(GeoArea)
10
11
  export class GeoAreaQuery {
11
12
  @Query(returns => GeoArea, { description: 'To fetch a GeoArea' })
12
- async geoArea(@Arg('id') id: string, @Ctx() context: any): Promise<GeoArea> {
13
+ async geoArea(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoArea> {
13
14
  return await getRepository(GeoArea).findOne({
14
15
  where: { id }
15
16
  })
16
17
  }
17
18
 
18
19
  @Query(returns => GeoAreaList, { description: 'To fetch multiple GeoAreas' })
19
- async geoAreas(@Args() params: ListParam, @Ctx() context: any): Promise<GeoAreaList> {
20
+ async geoAreas(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<GeoAreaList> {
20
21
  const convertedParams = convertListParams(params)
21
22
  const [items, total] = await getRepository(GeoArea).findAndCount(convertedParams)
22
23
 
23
24
  return { items, total }
24
25
  }
25
26
 
27
+ @Query(returns => GeoAreaList)
28
+ async geoAreasAllPostCode(@Ctx() context: ResolverContext) {
29
+ const result = await getRepository(GeoArea)
30
+ .createQueryBuilder('ga')
31
+ .select('ga.postal_code')
32
+ .distinct(true)
33
+ .orderBy('ga.postal_code')
34
+ .getRawMany()
35
+
36
+ const items: any[] = result.map(item => {
37
+ return {
38
+ postalCode: item.postal_code
39
+ }
40
+ })
41
+
42
+ const total = items.length
43
+
44
+ return { items, total }
45
+ }
46
+
47
+ @Query(returns => GeoArea)
48
+ async geoAreasGetStateAndCityByPosCode(@Arg('postCode') postCode: string, @Ctx() context: ResolverContext) {
49
+ let result = await getRepository(GeoArea)
50
+ .createQueryBuilder('ga')
51
+ .select('ga.city_name', 'cityName')
52
+ .addSelect('ga.state_name', 'stateName')
53
+ .distinct(true)
54
+ .where('ga.postal_code = :postCode', { postCode: postCode })
55
+ .getRawOne()
56
+
57
+ return result
58
+ }
59
+
26
60
  @FieldResolver(type => GeoCity)
27
61
  async geoCity(@Root() geoArea: GeoArea): Promise<GeoCity> {
28
- return await getRepository(GeoCity).findOne(geoArea.geoCityId)
62
+ return await getRepository(GeoCity).findOneBy({ id: geoArea.geoCityId })
29
63
  }
30
64
 
31
65
  @FieldResolver(type => User)
32
66
  async updater(@Root() geoArea: GeoArea): Promise<User> {
33
- return await getRepository(User).findOne(geoArea.updaterId)
67
+ return await getRepository(User).findOneBy({ id: geoArea.updaterId })
34
68
  }
35
69
 
36
70
  @FieldResolver(type => User)
37
71
  async creator(@Root() geoArea: GeoArea): Promise<User> {
38
- return await getRepository(User).findOne(geoArea.creatorId)
72
+ return await getRepository(User).findOneBy({ id: geoArea.creatorId })
39
73
  }
40
74
  }
@@ -13,7 +13,7 @@ import {
13
13
  import { GeoCity } from '../geo-city/geo-city'
14
14
 
15
15
  @Entity()
16
- @Index('ix_geo_area_0', (geoArea: GeoArea) => [geoArea.geoCity, geoArea.name], { unique: true })
16
+ @Index('ix_geo_area_0', (geoArea: GeoArea) => [geoArea.geoCity, geoArea.name, geoArea.postalCode,geoArea.stateName], { unique: true })
17
17
  @ObjectType({ description: 'Entity for GeoArea' })
18
18
  export class GeoArea {
19
19
  @PrimaryGeneratedColumn('uuid')
@@ -1,5 +1,6 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
2
  import { In } from 'typeorm'
3
+
3
4
  import { GeoCity } from './geo-city'
4
5
  import { GeoCityPatch, NewGeoCity } from './geo-city-type'
5
6
 
@@ -7,7 +8,7 @@ import { GeoCityPatch, NewGeoCity } from './geo-city-type'
7
8
  export class GeoCityMutation {
8
9
  @Directive('@transaction')
9
10
  @Mutation(returns => GeoCity, { description: 'To create new GeoCity' })
10
- async createGeoCity(@Arg('geoCity') geoCity: NewGeoCity, @Ctx() context: any): Promise<GeoCity> {
11
+ async createGeoCity(@Arg('geoCity') geoCity: NewGeoCity, @Ctx() context: ResolverContext): Promise<GeoCity> {
11
12
  const { user, tx } = context.state
12
13
 
13
14
  return await tx.getRepository(GeoCity).save({
@@ -19,7 +20,11 @@ export class GeoCityMutation {
19
20
 
20
21
  @Directive('@transaction')
21
22
  @Mutation(returns => GeoCity, { description: 'To modify GeoCity information' })
22
- async updateGeoCity(@Arg('id') id: string, @Arg('patch') patch: GeoCityPatch, @Ctx() context: any): Promise<GeoCity> {
23
+ async updateGeoCity(
24
+ @Arg('id') id: string,
25
+ @Arg('patch') patch: GeoCityPatch,
26
+ @Ctx() context: ResolverContext
27
+ ): Promise<GeoCity> {
23
28
  const { user, tx } = context.state
24
29
 
25
30
  const repository = tx.getRepository(GeoCity)
@@ -38,7 +43,7 @@ export class GeoCityMutation {
38
43
  @Mutation(returns => [GeoCity], { description: "To modify multiple GeoCities' information" })
39
44
  async updateMultipleGeoCity(
40
45
  @Arg('patches', type => [GeoCityPatch]) patches: GeoCityPatch[],
41
- @Ctx() context: any
46
+ @Ctx() context: ResolverContext
42
47
  ): Promise<GeoCity[]> {
43
48
  const { user, tx } = context.state
44
49
 
@@ -64,7 +69,7 @@ export class GeoCityMutation {
64
69
  if (_updateRecords.length > 0) {
65
70
  for (let i = 0; i < _updateRecords.length; i++) {
66
71
  const newRecord = _updateRecords[i]
67
- const geoCity = await geoCityRepo.findOne(newRecord.id)
72
+ const geoCity = await geoCityRepo.findOneBy({ id: newRecord.id })
68
73
 
69
74
  const result = await geoCityRepo.save({
70
75
  ...geoCity,
@@ -81,7 +86,7 @@ export class GeoCityMutation {
81
86
 
82
87
  @Directive('@transaction')
83
88
  @Mutation(returns => Boolean, { description: 'To delete GeoCity' })
84
- async deleteGeoCity(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
89
+ async deleteGeoCity(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
85
90
  const { tx } = context.state
86
91
 
87
92
  await tx.getRepository(GeoCity).delete({ id })
@@ -90,7 +95,10 @@ export class GeoCityMutation {
90
95
 
91
96
  @Directive('@transaction')
92
97
  @Mutation(returns => Boolean, { description: 'To delete multiple geoCitys' })
93
- async deleteGeoCities(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
98
+ async deleteGeoCities(
99
+ @Arg('ids', type => [String]) ids: string[],
100
+ @Ctx() context: ResolverContext
101
+ ): Promise<boolean> {
94
102
  const { tx } = context.state
95
103
 
96
104
  await tx.getRepository(GeoCity).delete({
@@ -1,7 +1,8 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { convertListParams, ListParam } from '@things-factory/shell'
3
1
  import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
4
- import { getRepository } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
5
+
5
6
  import { GeoCountry } from '../geo-country/geo-country'
6
7
  import { GeoState } from '../geo-state/geo-state'
7
8
  import { GeoCity } from './geo-city'
@@ -10,14 +11,14 @@ import { GeoCityList } from './geo-city-type'
10
11
  @Resolver(GeoCity)
11
12
  export class GeoCityQuery {
12
13
  @Query(returns => GeoCity, { description: 'To fetch a GeoCity' })
13
- async geoCity(@Arg('id') id: string, @Ctx() context: any): Promise<GeoCity> {
14
+ async geoCity(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoCity> {
14
15
  return await getRepository(GeoCity).findOne({
15
16
  where: { id }
16
17
  })
17
18
  }
18
19
 
19
20
  @Query(returns => GeoCityList, { description: 'To fetch multiple GeoCities' })
20
- async geoCities(@Args() params: ListParam, @Ctx() context: any): Promise<GeoCityList> {
21
+ async geoCities(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<GeoCityList> {
21
22
  const convertedParams = convertListParams(params)
22
23
  const [items, total] = await getRepository(GeoCity).findAndCount(convertedParams)
23
24
 
@@ -26,21 +27,21 @@ export class GeoCityQuery {
26
27
 
27
28
  @FieldResolver(type => GeoCountry)
28
29
  async geoCountry(@Root() geoCity: GeoCity): Promise<GeoCountry> {
29
- return await getRepository(GeoCountry).findOne(geoCity.geoCountryId)
30
+ return await getRepository(GeoCountry).findOneBy({ id: geoCity.geoCountryId })
30
31
  }
31
32
 
32
33
  @FieldResolver(type => GeoState)
33
34
  async geoState(@Root() geoCity: GeoCity): Promise<GeoState> {
34
- return await getRepository(GeoState).findOne(geoCity.geoStateId)
35
+ return await getRepository(GeoState).findOneBy({ id: geoCity.geoStateId })
35
36
  }
36
37
 
37
38
  @FieldResolver(type => User)
38
39
  async updater(@Root() geoCity: GeoCity): Promise<User> {
39
- return await getRepository(User).findOne(geoCity.updaterId)
40
+ return await getRepository(User).findOneBy({ id: geoCity.updaterId })
40
41
  }
41
42
 
42
43
  @FieldResolver(type => User)
43
44
  async creator(@Root() geoCity: GeoCity): Promise<User> {
44
- return await getRepository(User).findOne(geoCity.creatorId)
45
+ return await getRepository(User).findOneBy({ id: geoCity.creatorId })
45
46
  }
46
47
  }
@@ -14,7 +14,7 @@ import { GeoCountry } from '../geo-country/geo-country'
14
14
  import { GeoState } from '../geo-state/geo-state'
15
15
 
16
16
  @Entity()
17
- @Index('ix_geo_city_0', (geoCity: GeoCity) => [geoCity.geoCountry, geoCity.name], { unique: true })
17
+ @Index('ix_geo_city_0', (geoCity: GeoCity) => [geoCity.geoCountry, geoCity.name, geoCity.geoState], { unique: true })
18
18
  @ObjectType({ description: 'Entity for GeoCity' })
19
19
  export class GeoCity {
20
20
  @PrimaryGeneratedColumn('uuid')
@@ -1,5 +1,6 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
2
  import { In } from 'typeorm'
3
+
3
4
  import { GeoContinent } from './geo-continent'
4
5
  import { GeoContinentPatch, NewGeoContinent } from './geo-continent-type'
5
6
 
@@ -9,7 +10,7 @@ export class GeoContinentMutation {
9
10
  @Mutation(returns => GeoContinent, { description: 'To create new GeoContinent' })
10
11
  async createGeoContinent(
11
12
  @Arg('geoContinent') geoContinent: NewGeoContinent,
12
- @Ctx() context: any
13
+ @Ctx() context: ResolverContext
13
14
  ): Promise<GeoContinent> {
14
15
  const { user, tx } = context.state
15
16
 
@@ -25,7 +26,7 @@ export class GeoContinentMutation {
25
26
  async updateGeoContinent(
26
27
  @Arg('id') id: string,
27
28
  @Arg('patch') patch: GeoContinentPatch,
28
- @Ctx() context: any
29
+ @Ctx() context: ResolverContext
29
30
  ): Promise<GeoContinent> {
30
31
  const { user, tx } = context.state
31
32
 
@@ -45,7 +46,7 @@ export class GeoContinentMutation {
45
46
  @Mutation(returns => [GeoContinent], { description: "To modify multiple GeoContinents' information" })
46
47
  async updateMultipleGeoContinent(
47
48
  @Arg('patches', type => [GeoContinentPatch]) patches: GeoContinentPatch[],
48
- @Ctx() context: any
49
+ @Ctx() context: ResolverContext
49
50
  ): Promise<GeoContinent[]> {
50
51
  const { user, tx } = context.state
51
52
 
@@ -71,7 +72,7 @@ export class GeoContinentMutation {
71
72
  if (_updateRecords.length > 0) {
72
73
  for (let i = 0; i < _updateRecords.length; i++) {
73
74
  const newRecord = _updateRecords[i]
74
- const geoContinent = await geoContinentRepo.findOne(newRecord.id)
75
+ const geoContinent = await geoContinentRepo.findOneBy({ id: newRecord.id })
75
76
 
76
77
  const result = await geoContinentRepo.save({
77
78
  ...geoContinent,
@@ -88,7 +89,7 @@ export class GeoContinentMutation {
88
89
 
89
90
  @Directive('@transaction')
90
91
  @Mutation(returns => Boolean, { description: 'To delete GeoContinent' })
91
- async deleteGeoContinent(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
92
+ async deleteGeoContinent(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
92
93
  const { tx } = context.state
93
94
 
94
95
  await tx.getRepository(GeoContinent).delete({ id })
@@ -97,7 +98,10 @@ export class GeoContinentMutation {
97
98
 
98
99
  @Directive('@transaction')
99
100
  @Mutation(returns => Boolean, { description: 'To delete multiple geoContinents' })
100
- async deleteGeoContinents(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
101
+ async deleteGeoContinents(
102
+ @Arg('ids', type => [String]) ids: string[],
103
+ @Ctx() context: ResolverContext
104
+ ): Promise<boolean> {
101
105
  const { tx } = context.state
102
106
 
103
107
  await tx.getRepository(GeoContinent).delete({
@@ -1,21 +1,22 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { convertListParams, ListParam } from '@things-factory/shell'
3
1
  import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
4
- import { getRepository } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
5
+
5
6
  import { GeoContinent } from './geo-continent'
6
7
  import { GeoContinentList } from './geo-continent-type'
7
8
 
8
9
  @Resolver(GeoContinent)
9
10
  export class GeoContinentQuery {
10
11
  @Query(returns => GeoContinent, { description: 'To fetch a GeoContinent' })
11
- async geoContinent(@Arg('id') id: string, @Ctx() context: any): Promise<GeoContinent> {
12
+ async geoContinent(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoContinent> {
12
13
  return await getRepository(GeoContinent).findOne({
13
14
  where: { id }
14
15
  })
15
16
  }
16
17
 
17
18
  @Query(returns => GeoContinentList, { description: 'To fetch multiple GeoContinents' })
18
- async geoContinents(@Args() params: ListParam, @Ctx() context: any): Promise<GeoContinentList> {
19
+ async geoContinents(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<GeoContinentList> {
19
20
  const convertedParams = convertListParams(params)
20
21
  const [items, total] = await getRepository(GeoContinent).findAndCount(convertedParams)
21
22
 
@@ -24,11 +25,11 @@ export class GeoContinentQuery {
24
25
 
25
26
  @FieldResolver(type => User)
26
27
  async updater(@Root() geoContinent: GeoContinent): Promise<User> {
27
- return await getRepository(User).findOne(geoContinent.updaterId)
28
+ return await getRepository(User).findOneBy({ id: geoContinent.updaterId })
28
29
  }
29
30
 
30
31
  @FieldResolver(type => User)
31
32
  async creator(@Root() geoContinent: GeoContinent): Promise<User> {
32
- return await getRepository(User).findOne(geoContinent.creatorId)
33
+ return await getRepository(User).findOneBy({ id: geoContinent.creatorId })
33
34
  }
34
35
  }
@@ -1,5 +1,6 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
2
  import { In } from 'typeorm'
3
+
3
4
  import { GeoCountry } from './geo-country'
4
5
  import { GeoCountryPatch, NewGeoCountry } from './geo-country-type'
5
6
 
@@ -7,7 +8,10 @@ import { GeoCountryPatch, NewGeoCountry } from './geo-country-type'
7
8
  export class GeoCountryMutation {
8
9
  @Directive('@transaction')
9
10
  @Mutation(returns => GeoCountry, { description: 'To create new GeoCountry' })
10
- async createGeoCountry(@Arg('geoCountry') geoCountry: NewGeoCountry, @Ctx() context: any): Promise<GeoCountry> {
11
+ async createGeoCountry(
12
+ @Arg('geoCountry') geoCountry: NewGeoCountry,
13
+ @Ctx() context: ResolverContext
14
+ ): Promise<GeoCountry> {
11
15
  const { user, tx } = context.state
12
16
 
13
17
  return await tx.getRepository(GeoCountry).save({
@@ -22,7 +26,7 @@ export class GeoCountryMutation {
22
26
  async updateGeoCountry(
23
27
  @Arg('id') id: string,
24
28
  @Arg('patch') patch: GeoCountryPatch,
25
- @Ctx() context: any
29
+ @Ctx() context: ResolverContext
26
30
  ): Promise<GeoCountry> {
27
31
  const { user, tx } = context.state
28
32
 
@@ -42,7 +46,7 @@ export class GeoCountryMutation {
42
46
  @Mutation(returns => [GeoCountry], { description: "To modify multiple GeoCountries' information" })
43
47
  async updateMultipleGeoCountry(
44
48
  @Arg('patches', type => [GeoCountryPatch]) patches: GeoCountryPatch[],
45
- @Ctx() context: any
49
+ @Ctx() context: ResolverContext
46
50
  ): Promise<GeoCountry[]> {
47
51
  const { user, tx } = context.state
48
52
 
@@ -68,7 +72,7 @@ export class GeoCountryMutation {
68
72
  if (_updateRecords.length > 0) {
69
73
  for (let i = 0; i < _updateRecords.length; i++) {
70
74
  const newRecord = _updateRecords[i]
71
- const geoCountry = await geoCountryRepo.findOne(newRecord.id)
75
+ const geoCountry = await geoCountryRepo.findOneBy({ id: newRecord.id })
72
76
 
73
77
  const result = await geoCountryRepo.save({
74
78
  ...geoCountry,
@@ -85,7 +89,7 @@ export class GeoCountryMutation {
85
89
 
86
90
  @Directive('@transaction')
87
91
  @Mutation(returns => Boolean, { description: 'To delete GeoCountry' })
88
- async deleteGeoCountry(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
92
+ async deleteGeoCountry(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
89
93
  const { tx } = context.state
90
94
 
91
95
  await tx.getRepository(GeoCountry).delete({ id })
@@ -94,7 +98,10 @@ export class GeoCountryMutation {
94
98
 
95
99
  @Directive('@transaction')
96
100
  @Mutation(returns => Boolean, { description: 'To delete multiple geoCountrys' })
97
- async deleteGeoCountries(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
101
+ async deleteGeoCountries(
102
+ @Arg('ids', type => [String]) ids: string[],
103
+ @Ctx() context: ResolverContext
104
+ ): Promise<boolean> {
98
105
  const { tx } = context.state
99
106
 
100
107
  await tx.getRepository(GeoCountry).delete({
@@ -1,7 +1,8 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { convertListParams, ListParam } from '@things-factory/shell'
3
1
  import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
4
- import { getRepository } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
5
+
5
6
  import { GeoContinent } from '../geo-continent/geo-continent'
6
7
  import { GeoCountry } from './geo-country'
7
8
  import { GeoCountryList } from './geo-country-type'
@@ -9,32 +10,39 @@ import { GeoCountryList } from './geo-country-type'
9
10
  @Resolver(GeoCountry)
10
11
  export class GeoCountryQuery {
11
12
  @Query(returns => GeoCountry, { description: 'To fetch a GeoCountry' })
12
- async geoCountry(@Arg('id') id: string, @Ctx() context: any): Promise<GeoCountry> {
13
+ async geoCountry(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoCountry> {
13
14
  return await getRepository(GeoCountry).findOne({
14
15
  where: { id }
15
16
  })
16
17
  }
17
18
 
18
19
  @Query(returns => GeoCountryList, { description: 'To fetch multiple GeoCountries' })
19
- async geoCountries(@Args() params: ListParam, @Ctx() context: any): Promise<GeoCountryList> {
20
+ async geoCountries(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<GeoCountryList> {
20
21
  const convertedParams = convertListParams(params)
21
22
  const [items, total] = await getRepository(GeoCountry).findAndCount(convertedParams)
22
23
 
23
24
  return { items, total }
24
25
  }
25
26
 
27
+ @Query(returns => GeoCountryList, { description: 'To fetch multiple GeoCountries without params' })
28
+ async geoCountriesWithoutParam(@Ctx() context: ResolverContext): Promise<GeoCountryList> {
29
+ const [items, total] = await getRepository(GeoCountry).findAndCount()
30
+
31
+ return { items, total }
32
+ }
33
+
26
34
  @FieldResolver(type => GeoContinent)
27
35
  async geoContinent(@Root() geoCountry: GeoCountry): Promise<GeoContinent> {
28
- return await getRepository(GeoContinent).findOne(geoCountry.geoContinentId)
36
+ return await getRepository(GeoContinent).findOneBy({ id: geoCountry.geoContinentId })
29
37
  }
30
38
 
31
39
  @FieldResolver(type => User)
32
40
  async updater(@Root() geoCountry: GeoCountry): Promise<User> {
33
- return await getRepository(User).findOne(geoCountry.updaterId)
41
+ return await getRepository(User).findOneBy({ id: geoCountry.updaterId })
34
42
  }
35
43
 
36
44
  @FieldResolver(type => User)
37
45
  async creator(@Root() geoCountry: GeoCountry): Promise<User> {
38
- return await getRepository(User).findOne(geoCountry.creatorId)
46
+ return await getRepository(User).findOneBy({ id: geoCountry.creatorId })
39
47
  }
40
48
  }
@@ -1,5 +1,6 @@
1
1
  import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
2
  import { In } from 'typeorm'
3
+
3
4
  import { GeoState } from './geo-state'
4
5
  import { GeoStatePatch, NewGeoState } from './geo-state-type'
5
6
 
@@ -7,7 +8,7 @@ import { GeoStatePatch, NewGeoState } from './geo-state-type'
7
8
  export class GeoStateMutation {
8
9
  @Directive('@transaction')
9
10
  @Mutation(returns => GeoState, { description: 'To create new GeoState' })
10
- async createGeoState(@Arg('geoState') geoState: NewGeoState, @Ctx() context: any): Promise<GeoState> {
11
+ async createGeoState(@Arg('geoState') geoState: NewGeoState, @Ctx() context: ResolverContext): Promise<GeoState> {
11
12
  const { user, tx } = context.state
12
13
 
13
14
  return await tx.getRepository(GeoState).save({
@@ -22,7 +23,7 @@ export class GeoStateMutation {
22
23
  async updateGeoState(
23
24
  @Arg('id') id: string,
24
25
  @Arg('patch') patch: GeoStatePatch,
25
- @Ctx() context: any
26
+ @Ctx() context: ResolverContext
26
27
  ): Promise<GeoState> {
27
28
  const { user, tx } = context.state
28
29
 
@@ -42,7 +43,7 @@ export class GeoStateMutation {
42
43
  @Mutation(returns => [GeoState], { description: "To modify multiple GeoStates' information" })
43
44
  async updateMultipleGeoState(
44
45
  @Arg('patches', type => [GeoStatePatch]) patches: GeoStatePatch[],
45
- @Ctx() context: any
46
+ @Ctx() context: ResolverContext
46
47
  ): Promise<GeoState[]> {
47
48
  const { user, tx } = context.state
48
49
 
@@ -68,7 +69,7 @@ export class GeoStateMutation {
68
69
  if (_updateRecords.length > 0) {
69
70
  for (let i = 0; i < _updateRecords.length; i++) {
70
71
  const newRecord = _updateRecords[i]
71
- const geoState = await geoStateRepo.findOne(newRecord.id)
72
+ const geoState = await geoStateRepo.findOneBy({ id: newRecord.id })
72
73
 
73
74
  const result = await geoStateRepo.save({
74
75
  ...geoState,
@@ -85,7 +86,7 @@ export class GeoStateMutation {
85
86
 
86
87
  @Directive('@transaction')
87
88
  @Mutation(returns => Boolean, { description: 'To delete GeoState' })
88
- async deleteGeoState(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
89
+ async deleteGeoState(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
89
90
  const { tx } = context.state
90
91
 
91
92
  await tx.getRepository(GeoState).delete({ id })
@@ -94,7 +95,10 @@ export class GeoStateMutation {
94
95
 
95
96
  @Directive('@transaction')
96
97
  @Mutation(returns => Boolean, { description: 'To delete multiple geoStates' })
97
- async deleteGeoStates(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
98
+ async deleteGeoStates(
99
+ @Arg('ids', type => [String]) ids: string[],
100
+ @Ctx() context: ResolverContext
101
+ ): Promise<boolean> {
98
102
  const { tx } = context.state
99
103
 
100
104
  await tx.getRepository(GeoState).delete({
@@ -1,7 +1,8 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { convertListParams, ListParam } from '@things-factory/shell'
3
1
  import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
4
- import { getRepository } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
5
+
5
6
  import { GeoCountry } from '../geo-country/geo-country'
6
7
  import { GeoState } from './geo-state'
7
8
  import { GeoStateList } from './geo-state-type'
@@ -9,14 +10,14 @@ import { GeoStateList } from './geo-state-type'
9
10
  @Resolver(GeoState)
10
11
  export class GeoStateQuery {
11
12
  @Query(returns => GeoState, { description: 'To fetch a GeoState' })
12
- async geoState(@Arg('id') id: string, @Ctx() context: any): Promise<GeoState> {
13
+ async geoState(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoState> {
13
14
  return await getRepository(GeoState).findOne({
14
15
  where: { id }
15
16
  })
16
17
  }
17
18
 
18
19
  @Query(returns => GeoStateList, { description: 'To fetch multiple GeoStates' })
19
- async geoStates(@Args() params: ListParam, @Ctx() context: any): Promise<GeoStateList> {
20
+ async geoStates(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<GeoStateList> {
20
21
  const convertedParams = convertListParams(params)
21
22
  const [items, total] = await getRepository(GeoState).findAndCount(convertedParams)
22
23
 
@@ -25,16 +26,16 @@ export class GeoStateQuery {
25
26
 
26
27
  @FieldResolver(type => GeoCountry)
27
28
  async geoCountry(@Root() geoState: GeoState): Promise<GeoCountry> {
28
- return await getRepository(GeoCountry).findOne(geoState.geoCountryId)
29
+ return await getRepository(GeoCountry).findOneBy({ id: geoState.geoCountryId })
29
30
  }
30
31
 
31
32
  @FieldResolver(type => User)
32
33
  async updater(@Root() geoState: GeoState): Promise<User> {
33
- return await getRepository(User).findOne(geoState.updaterId)
34
+ return await getRepository(User).findOneBy({ id: geoState.updaterId })
34
35
  }
35
36
 
36
37
  @FieldResolver(type => User)
37
38
  async creator(@Root() geoState: GeoState): Promise<User> {
38
- return await getRepository(User).findOne(geoState.creatorId)
39
+ return await getRepository(User).findOneBy({ id: geoState.creatorId })
39
40
  }
40
41
  }