@things-factory/geography 8.0.0-beta.1 → 8.0.0-beta.4
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/package.json +4 -4
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +0 -5
- package/server/middlewares/index.ts +0 -3
- package/server/migrations/index.ts +0 -9
- package/server/routes.ts +0 -26
- package/server/service/geo-area/geo-area-mutation.ts +0 -107
- package/server/service/geo-area/geo-area-query.ts +0 -74
- package/server/service/geo-area/geo-area-type.ts +0 -71
- package/server/service/geo-area/geo-area.ts +0 -85
- package/server/service/geo-area/index.ts +0 -6
- package/server/service/geo-city/geo-city-mutation.ts +0 -110
- package/server/service/geo-city/geo-city-query.ts +0 -47
- package/server/service/geo-city/geo-city-type.ts +0 -47
- package/server/service/geo-city/geo-city.ts +0 -81
- package/server/service/geo-city/index.ts +0 -6
- package/server/service/geo-continent/geo-continent-mutation.ts +0 -113
- package/server/service/geo-continent/geo-continent-query.ts +0 -38
- package/server/service/geo-continent/geo-continent-type.ts +0 -35
- package/server/service/geo-continent/geo-continent.ts +0 -57
- package/server/service/geo-continent/index.ts +0 -6
- package/server/service/geo-country/geo-country-mutation.ts +0 -113
- package/server/service/geo-country/geo-country-query.ts +0 -51
- package/server/service/geo-country/geo-country-type.ts +0 -41
- package/server/service/geo-country/geo-country.ts +0 -69
- package/server/service/geo-country/index.ts +0 -6
- package/server/service/geo-state/geo-state-mutation.ts +0 -110
- package/server/service/geo-state/geo-state-query.ts +0 -41
- package/server/service/geo-state/geo-state-type.ts +0 -47
- package/server/service/geo-state/geo-state.ts +0 -73
- package/server/service/geo-state/index.ts +0 -6
- package/server/service/index.ts +0 -33
- package/tsconfig.json +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/geography",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.4",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/auth-base": "^8.0.0-beta.
|
|
28
|
-
"@things-factory/shell": "^8.0.0-beta.
|
|
27
|
+
"@things-factory/auth-base": "^8.0.0-beta.4",
|
|
28
|
+
"@things-factory/shell": "^8.0.0-beta.4"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d83d12ed4ba07177dff1dac26e37be347d156b43"
|
|
31
31
|
}
|
|
File without changes
|
package/server/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const glob = require('glob')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
export var migrations = []
|
|
5
|
-
|
|
6
|
-
glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
|
|
7
|
-
if (file.indexOf('index.js') !== -1) return
|
|
8
|
-
migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
|
|
9
|
-
})
|
package/server/routes.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
2
|
-
/*
|
|
3
|
-
* can add global public routes to application (auth not required, tenancy not required)
|
|
4
|
-
*
|
|
5
|
-
* ex) routes.get('/path', async(context, next) => {})
|
|
6
|
-
* ex) routes.post('/path', async(context, next) => {})
|
|
7
|
-
*/
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
|
|
11
|
-
/*
|
|
12
|
-
* can add global private routes to application (auth required, tenancy not required)
|
|
13
|
-
*/
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
|
|
17
|
-
/*
|
|
18
|
-
* can add domain public routes to application (auth not required, tenancy required)
|
|
19
|
-
*/
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
23
|
-
/*
|
|
24
|
-
* can add domain private routes to application (auth required, tenancy required)
|
|
25
|
-
*/
|
|
26
|
-
})
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { GeoArea } from './geo-area'
|
|
5
|
-
import { GeoAreaPatch, NewGeoArea } from './geo-area-type'
|
|
6
|
-
|
|
7
|
-
@Resolver(GeoArea)
|
|
8
|
-
export class GeoAreaMutation {
|
|
9
|
-
@Directive('@transaction')
|
|
10
|
-
@Mutation(returns => GeoArea, { description: 'To create new GeoArea' })
|
|
11
|
-
async createGeoArea(@Arg('geoArea') geoArea: NewGeoArea, @Ctx() context: ResolverContext): Promise<GeoArea> {
|
|
12
|
-
const { user, tx } = context.state
|
|
13
|
-
|
|
14
|
-
return await tx.getRepository(GeoArea).save({
|
|
15
|
-
...geoArea,
|
|
16
|
-
creator: user,
|
|
17
|
-
updater: user
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Directive('@transaction')
|
|
22
|
-
@Mutation(returns => GeoArea, { description: 'To modify GeoArea information' })
|
|
23
|
-
async updateGeoArea(
|
|
24
|
-
@Arg('id') id: string,
|
|
25
|
-
@Arg('patch') patch: GeoAreaPatch,
|
|
26
|
-
@Ctx() context: ResolverContext
|
|
27
|
-
): Promise<GeoArea> {
|
|
28
|
-
const { user, tx } = context.state
|
|
29
|
-
|
|
30
|
-
const repository = tx.getRepository(GeoArea)
|
|
31
|
-
const geoArea = await repository.findOne({
|
|
32
|
-
where: { id }
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return await repository.save({
|
|
36
|
-
...geoArea,
|
|
37
|
-
...patch,
|
|
38
|
-
updater: user
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@Directive('@transaction')
|
|
43
|
-
@Mutation(returns => [GeoArea], { description: "To modify multiple GeoAreas' information" })
|
|
44
|
-
async updateMultipleGeoArea(
|
|
45
|
-
@Arg('patches', type => [GeoAreaPatch]) patches: GeoAreaPatch[],
|
|
46
|
-
@Ctx() context: ResolverContext
|
|
47
|
-
): Promise<GeoArea[]> {
|
|
48
|
-
const { user, tx } = context.state
|
|
49
|
-
|
|
50
|
-
let results = []
|
|
51
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
52
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
53
|
-
const geoAreaRepo = tx.getRepository(GeoArea)
|
|
54
|
-
|
|
55
|
-
if (_createRecords.length > 0) {
|
|
56
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
57
|
-
const newRecord = _createRecords[i]
|
|
58
|
-
|
|
59
|
-
const result = await geoAreaRepo.save({
|
|
60
|
-
...newRecord,
|
|
61
|
-
creator: user,
|
|
62
|
-
updater: user
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
results.push({ ...result, cuFlag: '+' })
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (_updateRecords.length > 0) {
|
|
70
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
71
|
-
const newRecord = _updateRecords[i]
|
|
72
|
-
const geoArea = await geoAreaRepo.findOneBy({ id: newRecord.id })
|
|
73
|
-
|
|
74
|
-
const result = await geoAreaRepo.save({
|
|
75
|
-
...geoArea,
|
|
76
|
-
...newRecord,
|
|
77
|
-
updater: user
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return results
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@Directive('@transaction')
|
|
88
|
-
@Mutation(returns => Boolean, { description: 'To delete GeoArea' })
|
|
89
|
-
async deleteGeoArea(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
90
|
-
const { tx } = context.state
|
|
91
|
-
|
|
92
|
-
await tx.getRepository(GeoArea).delete({ id })
|
|
93
|
-
return true
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@Directive('@transaction')
|
|
97
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple geoAreas' })
|
|
98
|
-
async deleteGeoAreas(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
|
|
99
|
-
const { domain, tx } = context.state
|
|
100
|
-
|
|
101
|
-
await tx.getRepository(GeoArea).delete({
|
|
102
|
-
id: In(ids)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
return true
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
4
|
-
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { GeoCity } from '../geo-city/geo-city'
|
|
7
|
-
import { GeoArea } from './geo-area'
|
|
8
|
-
import { GeoAreaList } from './geo-area-type'
|
|
9
|
-
|
|
10
|
-
@Resolver(GeoArea)
|
|
11
|
-
export class GeoAreaQuery {
|
|
12
|
-
@Query(returns => GeoArea, { description: 'To fetch a GeoArea' })
|
|
13
|
-
async geoArea(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoArea> {
|
|
14
|
-
return await getRepository(GeoArea).findOne({
|
|
15
|
-
where: { id }
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Query(returns => GeoAreaList, { description: 'To fetch multiple GeoAreas' })
|
|
20
|
-
async geoAreas(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<GeoAreaList> {
|
|
21
|
-
const convertedParams = convertListParams(params)
|
|
22
|
-
const [items, total] = await getRepository(GeoArea).findAndCount(convertedParams)
|
|
23
|
-
|
|
24
|
-
return { items, total }
|
|
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
|
-
|
|
60
|
-
@FieldResolver(type => GeoCity)
|
|
61
|
-
async geoCity(@Root() geoArea: GeoArea): Promise<GeoCity> {
|
|
62
|
-
return await getRepository(GeoCity).findOneBy({ id: geoArea.geoCityId })
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@FieldResolver(type => User)
|
|
66
|
-
async updater(@Root() geoArea: GeoArea): Promise<User> {
|
|
67
|
-
return await getRepository(User).findOneBy({ id: geoArea.updaterId })
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@FieldResolver(type => User)
|
|
71
|
-
async creator(@Root() geoArea: GeoArea): Promise<User> {
|
|
72
|
-
return await getRepository(User).findOneBy({ id: geoArea.creatorId })
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
import { GeoArea } from './geo-area'
|
|
3
|
-
|
|
4
|
-
@InputType()
|
|
5
|
-
export class NewGeoArea {
|
|
6
|
-
@Field()
|
|
7
|
-
name: string
|
|
8
|
-
|
|
9
|
-
@Field({ nullable: true })
|
|
10
|
-
description?: string
|
|
11
|
-
|
|
12
|
-
@Field({ nullable: true })
|
|
13
|
-
countryCode?: string
|
|
14
|
-
|
|
15
|
-
@Field({ nullable: true })
|
|
16
|
-
cityName?: string
|
|
17
|
-
|
|
18
|
-
@Field({ nullable: true })
|
|
19
|
-
stateName?: string
|
|
20
|
-
|
|
21
|
-
@Field({ nullable: true })
|
|
22
|
-
postalCode?: string
|
|
23
|
-
|
|
24
|
-
@Field({ nullable: true })
|
|
25
|
-
latitude?: string
|
|
26
|
-
|
|
27
|
-
@Field({ nullable: true })
|
|
28
|
-
longitude?: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@InputType()
|
|
32
|
-
export class GeoAreaPatch {
|
|
33
|
-
@Field(type => ID, { nullable: true })
|
|
34
|
-
id?: string
|
|
35
|
-
|
|
36
|
-
@Field({ nullable: true })
|
|
37
|
-
name?: string
|
|
38
|
-
|
|
39
|
-
@Field({ nullable: true })
|
|
40
|
-
description?: string
|
|
41
|
-
|
|
42
|
-
@Field({ nullable: true })
|
|
43
|
-
countryCode?: string
|
|
44
|
-
|
|
45
|
-
@Field({ nullable: true })
|
|
46
|
-
cityName?: string
|
|
47
|
-
|
|
48
|
-
@Field({ nullable: true })
|
|
49
|
-
stateName?: string
|
|
50
|
-
|
|
51
|
-
@Field({ nullable: true })
|
|
52
|
-
postalCode?: string
|
|
53
|
-
|
|
54
|
-
@Field({ nullable: true })
|
|
55
|
-
latitude?: string
|
|
56
|
-
|
|
57
|
-
@Field({ nullable: true })
|
|
58
|
-
longitude?: string
|
|
59
|
-
|
|
60
|
-
@Field()
|
|
61
|
-
cuFlag: string
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@ObjectType()
|
|
65
|
-
export class GeoAreaList {
|
|
66
|
-
@Field(type => [GeoArea])
|
|
67
|
-
items: GeoArea[]
|
|
68
|
-
|
|
69
|
-
@Field(type => Int)
|
|
70
|
-
total: number
|
|
71
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { User } from '@things-factory/auth-base'
|
|
2
|
-
import { Field, ID, ObjectType } from 'type-graphql'
|
|
3
|
-
import {
|
|
4
|
-
Column,
|
|
5
|
-
CreateDateColumn,
|
|
6
|
-
Entity,
|
|
7
|
-
Index,
|
|
8
|
-
ManyToOne,
|
|
9
|
-
PrimaryGeneratedColumn,
|
|
10
|
-
RelationId,
|
|
11
|
-
UpdateDateColumn
|
|
12
|
-
} from 'typeorm'
|
|
13
|
-
import { GeoCity } from '../geo-city/geo-city'
|
|
14
|
-
|
|
15
|
-
@Entity()
|
|
16
|
-
@Index('ix_geo_area_0', (geoArea: GeoArea) => [geoArea.geoCity, geoArea.name, geoArea.postalCode, geoArea.stateName], {
|
|
17
|
-
unique: true
|
|
18
|
-
})
|
|
19
|
-
@ObjectType({ description: 'Entity for GeoArea' })
|
|
20
|
-
export class GeoArea {
|
|
21
|
-
@PrimaryGeneratedColumn('uuid')
|
|
22
|
-
@Field(type => ID)
|
|
23
|
-
readonly id: string
|
|
24
|
-
|
|
25
|
-
@ManyToOne(type => GeoCity)
|
|
26
|
-
@Field({ nullable: true })
|
|
27
|
-
geoCity?: GeoCity
|
|
28
|
-
|
|
29
|
-
@RelationId((geoArea: GeoArea) => geoArea.geoCity)
|
|
30
|
-
geoCityId?: string
|
|
31
|
-
|
|
32
|
-
@Column()
|
|
33
|
-
@Field()
|
|
34
|
-
name: string
|
|
35
|
-
|
|
36
|
-
@Column({ nullable: true })
|
|
37
|
-
@Field({ nullable: true })
|
|
38
|
-
description?: string
|
|
39
|
-
|
|
40
|
-
@Column({ nullable: true })
|
|
41
|
-
@Field({ nullable: true })
|
|
42
|
-
countryCode?: string
|
|
43
|
-
|
|
44
|
-
@Column({ nullable: true })
|
|
45
|
-
@Field({ nullable: true })
|
|
46
|
-
cityName?: string
|
|
47
|
-
|
|
48
|
-
@Column({ nullable: true })
|
|
49
|
-
@Field({ nullable: true })
|
|
50
|
-
stateName?: string
|
|
51
|
-
|
|
52
|
-
@Column({ nullable: true })
|
|
53
|
-
@Field({ nullable: true })
|
|
54
|
-
postalCode?: string
|
|
55
|
-
|
|
56
|
-
@Column({ nullable: true })
|
|
57
|
-
@Field({ nullable: true })
|
|
58
|
-
latitude?: string
|
|
59
|
-
|
|
60
|
-
@Column({ nullable: true })
|
|
61
|
-
@Field({ nullable: true })
|
|
62
|
-
longitude?: string
|
|
63
|
-
|
|
64
|
-
@CreateDateColumn()
|
|
65
|
-
@Field({ nullable: true })
|
|
66
|
-
createdAt?: Date
|
|
67
|
-
|
|
68
|
-
@UpdateDateColumn()
|
|
69
|
-
@Field({ nullable: true })
|
|
70
|
-
updatedAt?: Date
|
|
71
|
-
|
|
72
|
-
@ManyToOne(type => User, { nullable: true })
|
|
73
|
-
@Field(type => User, { nullable: true })
|
|
74
|
-
creator?: User
|
|
75
|
-
|
|
76
|
-
@RelationId((geoArea: GeoArea) => geoArea.creator)
|
|
77
|
-
creatorId?: string
|
|
78
|
-
|
|
79
|
-
@ManyToOne(type => User, { nullable: true })
|
|
80
|
-
@Field(type => User, { nullable: true })
|
|
81
|
-
updater?: User
|
|
82
|
-
|
|
83
|
-
@RelationId((geoArea: GeoArea) => geoArea.updater)
|
|
84
|
-
updaterId?: string
|
|
85
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { GeoCity } from './geo-city'
|
|
5
|
-
import { GeoCityPatch, NewGeoCity } from './geo-city-type'
|
|
6
|
-
|
|
7
|
-
@Resolver(GeoCity)
|
|
8
|
-
export class GeoCityMutation {
|
|
9
|
-
@Directive('@transaction')
|
|
10
|
-
@Mutation(returns => GeoCity, { description: 'To create new GeoCity' })
|
|
11
|
-
async createGeoCity(@Arg('geoCity') geoCity: NewGeoCity, @Ctx() context: ResolverContext): Promise<GeoCity> {
|
|
12
|
-
const { user, tx } = context.state
|
|
13
|
-
|
|
14
|
-
return await tx.getRepository(GeoCity).save({
|
|
15
|
-
...geoCity,
|
|
16
|
-
creator: user,
|
|
17
|
-
updater: user
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Directive('@transaction')
|
|
22
|
-
@Mutation(returns => GeoCity, { description: 'To modify GeoCity information' })
|
|
23
|
-
async updateGeoCity(
|
|
24
|
-
@Arg('id') id: string,
|
|
25
|
-
@Arg('patch') patch: GeoCityPatch,
|
|
26
|
-
@Ctx() context: ResolverContext
|
|
27
|
-
): Promise<GeoCity> {
|
|
28
|
-
const { user, tx } = context.state
|
|
29
|
-
|
|
30
|
-
const repository = tx.getRepository(GeoCity)
|
|
31
|
-
const geoCity = await repository.findOne({
|
|
32
|
-
where: { id }
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return await repository.save({
|
|
36
|
-
...geoCity,
|
|
37
|
-
...patch,
|
|
38
|
-
updater: user
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@Directive('@transaction')
|
|
43
|
-
@Mutation(returns => [GeoCity], { description: "To modify multiple GeoCities' information" })
|
|
44
|
-
async updateMultipleGeoCity(
|
|
45
|
-
@Arg('patches', type => [GeoCityPatch]) patches: GeoCityPatch[],
|
|
46
|
-
@Ctx() context: ResolverContext
|
|
47
|
-
): Promise<GeoCity[]> {
|
|
48
|
-
const { user, tx } = context.state
|
|
49
|
-
|
|
50
|
-
let results = []
|
|
51
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
52
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
53
|
-
const geoCityRepo = tx.getRepository(GeoCity)
|
|
54
|
-
|
|
55
|
-
if (_createRecords.length > 0) {
|
|
56
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
57
|
-
const newRecord = _createRecords[i]
|
|
58
|
-
|
|
59
|
-
const result = await geoCityRepo.save({
|
|
60
|
-
...newRecord,
|
|
61
|
-
creator: user,
|
|
62
|
-
updater: user
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
results.push({ ...result, cuFlag: '+' })
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (_updateRecords.length > 0) {
|
|
70
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
71
|
-
const newRecord = _updateRecords[i]
|
|
72
|
-
const geoCity = await geoCityRepo.findOneBy({ id: newRecord.id })
|
|
73
|
-
|
|
74
|
-
const result = await geoCityRepo.save({
|
|
75
|
-
...geoCity,
|
|
76
|
-
...newRecord,
|
|
77
|
-
updater: user
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return results
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@Directive('@transaction')
|
|
88
|
-
@Mutation(returns => Boolean, { description: 'To delete GeoCity' })
|
|
89
|
-
async deleteGeoCity(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
90
|
-
const { tx } = context.state
|
|
91
|
-
|
|
92
|
-
await tx.getRepository(GeoCity).delete({ id })
|
|
93
|
-
return true
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@Directive('@transaction')
|
|
97
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple geoCitys' })
|
|
98
|
-
async deleteGeoCities(
|
|
99
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
100
|
-
@Ctx() context: ResolverContext
|
|
101
|
-
): Promise<boolean> {
|
|
102
|
-
const { tx } = context.state
|
|
103
|
-
|
|
104
|
-
await tx.getRepository(GeoCity).delete({
|
|
105
|
-
id: In(ids)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
return true
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
4
|
-
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { GeoCountry } from '../geo-country/geo-country'
|
|
7
|
-
import { GeoState } from '../geo-state/geo-state'
|
|
8
|
-
import { GeoCity } from './geo-city'
|
|
9
|
-
import { GeoCityList } from './geo-city-type'
|
|
10
|
-
|
|
11
|
-
@Resolver(GeoCity)
|
|
12
|
-
export class GeoCityQuery {
|
|
13
|
-
@Query(returns => GeoCity, { description: 'To fetch a GeoCity' })
|
|
14
|
-
async geoCity(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoCity> {
|
|
15
|
-
return await getRepository(GeoCity).findOne({
|
|
16
|
-
where: { id }
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Query(returns => GeoCityList, { description: 'To fetch multiple GeoCities' })
|
|
21
|
-
async geoCities(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<GeoCityList> {
|
|
22
|
-
const convertedParams = convertListParams(params)
|
|
23
|
-
const [items, total] = await getRepository(GeoCity).findAndCount(convertedParams)
|
|
24
|
-
|
|
25
|
-
return { items, total }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@FieldResolver(type => GeoCountry)
|
|
29
|
-
async geoCountry(@Root() geoCity: GeoCity): Promise<GeoCountry> {
|
|
30
|
-
return await getRepository(GeoCountry).findOneBy({ id: geoCity.geoCountryId })
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@FieldResolver(type => GeoState)
|
|
34
|
-
async geoState(@Root() geoCity: GeoCity): Promise<GeoState> {
|
|
35
|
-
return await getRepository(GeoState).findOneBy({ id: geoCity.geoStateId })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@FieldResolver(type => User)
|
|
39
|
-
async updater(@Root() geoCity: GeoCity): Promise<User> {
|
|
40
|
-
return await getRepository(User).findOneBy({ id: geoCity.updaterId })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@FieldResolver(type => User)
|
|
44
|
-
async creator(@Root() geoCity: GeoCity): Promise<User> {
|
|
45
|
-
return await getRepository(User).findOneBy({ id: geoCity.creatorId })
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
import { GeoCity } from './geo-city'
|
|
3
|
-
|
|
4
|
-
@InputType()
|
|
5
|
-
export class NewGeoCity {
|
|
6
|
-
@Field()
|
|
7
|
-
name: string
|
|
8
|
-
|
|
9
|
-
@Field({ nullable: true })
|
|
10
|
-
description?: string
|
|
11
|
-
|
|
12
|
-
@Field({ nullable: true })
|
|
13
|
-
latitude?: string
|
|
14
|
-
|
|
15
|
-
@Field({ nullable: true })
|
|
16
|
-
longitude?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@InputType()
|
|
20
|
-
export class GeoCityPatch {
|
|
21
|
-
@Field(type => ID, { nullable: true })
|
|
22
|
-
id?: string
|
|
23
|
-
|
|
24
|
-
@Field({ nullable: true })
|
|
25
|
-
name?: string
|
|
26
|
-
|
|
27
|
-
@Field({ nullable: true })
|
|
28
|
-
description?: string
|
|
29
|
-
|
|
30
|
-
@Field({ nullable: true })
|
|
31
|
-
latitude?: string
|
|
32
|
-
|
|
33
|
-
@Field({ nullable: true })
|
|
34
|
-
longitude?: string
|
|
35
|
-
|
|
36
|
-
@Field()
|
|
37
|
-
cuFlag: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@ObjectType()
|
|
41
|
-
export class GeoCityList {
|
|
42
|
-
@Field(type => [GeoCity])
|
|
43
|
-
items: GeoCity[]
|
|
44
|
-
|
|
45
|
-
@Field(type => Int)
|
|
46
|
-
total: number
|
|
47
|
-
}
|