@things-factory/geography 8.0.0-beta.9 → 8.0.2
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/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +5 -0
- package/server/middlewares/index.ts +3 -0
- package/server/migrations/index.ts +9 -0
- package/server/routes.ts +26 -0
- package/server/service/geo-area/geo-area-mutation.ts +107 -0
- package/server/service/geo-area/geo-area-query.ts +74 -0
- package/server/service/geo-area/geo-area-type.ts +71 -0
- package/server/service/geo-area/geo-area.ts +85 -0
- package/server/service/geo-area/index.ts +6 -0
- package/server/service/geo-city/geo-city-mutation.ts +110 -0
- package/server/service/geo-city/geo-city-query.ts +47 -0
- package/server/service/geo-city/geo-city-type.ts +47 -0
- package/server/service/geo-city/geo-city.ts +81 -0
- package/server/service/geo-city/index.ts +6 -0
- package/server/service/geo-continent/geo-continent-mutation.ts +113 -0
- package/server/service/geo-continent/geo-continent-query.ts +38 -0
- package/server/service/geo-continent/geo-continent-type.ts +35 -0
- package/server/service/geo-continent/geo-continent.ts +57 -0
- package/server/service/geo-continent/index.ts +6 -0
- package/server/service/geo-country/geo-country-mutation.ts +113 -0
- package/server/service/geo-country/geo-country-query.ts +51 -0
- package/server/service/geo-country/geo-country-type.ts +41 -0
- package/server/service/geo-country/geo-country.ts +69 -0
- package/server/service/geo-country/index.ts +6 -0
- package/server/service/geo-state/geo-state-mutation.ts +110 -0
- package/server/service/geo-state/geo-state-query.ts +41 -0
- package/server/service/geo-state/geo-state-type.ts +47 -0
- package/server/service/geo-state/geo-state.ts +73 -0
- package/server/service/geo-state/index.ts +6 -0
- package/server/service/index.ts +33 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,81 @@
|
|
|
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 { GeoCountry } from '../geo-country/geo-country'
|
|
14
|
+
import { GeoState } from '../geo-state/geo-state'
|
|
15
|
+
|
|
16
|
+
@Entity()
|
|
17
|
+
@Index('ix_geo_city_0', (geoCity: GeoCity) => [geoCity.geoCountry, geoCity.name, geoCity.geoState], { unique: true })
|
|
18
|
+
@ObjectType({ description: 'Entity for GeoCity' })
|
|
19
|
+
export class GeoCity {
|
|
20
|
+
@PrimaryGeneratedColumn('uuid')
|
|
21
|
+
@Field(type => ID)
|
|
22
|
+
readonly id: string
|
|
23
|
+
|
|
24
|
+
@ManyToOne(type => GeoCountry)
|
|
25
|
+
@Field()
|
|
26
|
+
geoCountry: GeoCountry
|
|
27
|
+
|
|
28
|
+
@RelationId((geoCity: GeoCity) => geoCity.geoCountry)
|
|
29
|
+
geoCountryId?: string
|
|
30
|
+
|
|
31
|
+
@ManyToOne(type => GeoState)
|
|
32
|
+
@Field({ nullable: true })
|
|
33
|
+
geoState?: GeoState
|
|
34
|
+
|
|
35
|
+
@RelationId((geoCity: GeoCity) => geoCity.geoState)
|
|
36
|
+
geoStateId?: string
|
|
37
|
+
|
|
38
|
+
@Column()
|
|
39
|
+
@Field()
|
|
40
|
+
name: string
|
|
41
|
+
|
|
42
|
+
@Column({
|
|
43
|
+
nullable: true
|
|
44
|
+
})
|
|
45
|
+
@Field({ nullable: true })
|
|
46
|
+
description?: string
|
|
47
|
+
|
|
48
|
+
@Column({ nullable: true })
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
latitude?: string
|
|
51
|
+
|
|
52
|
+
@Column({ nullable: true })
|
|
53
|
+
@Field({ nullable: true })
|
|
54
|
+
longitude?: string
|
|
55
|
+
|
|
56
|
+
@CreateDateColumn()
|
|
57
|
+
@Field({ nullable: true })
|
|
58
|
+
createdAt?: Date
|
|
59
|
+
|
|
60
|
+
@UpdateDateColumn()
|
|
61
|
+
@Field({ nullable: true })
|
|
62
|
+
updatedAt?: Date
|
|
63
|
+
|
|
64
|
+
@ManyToOne(type => User, {
|
|
65
|
+
nullable: true
|
|
66
|
+
})
|
|
67
|
+
@Field(type => User, { nullable: true })
|
|
68
|
+
creator?: User
|
|
69
|
+
|
|
70
|
+
@RelationId((geoCity: GeoCity) => geoCity.creator)
|
|
71
|
+
creatorId?: string
|
|
72
|
+
|
|
73
|
+
@ManyToOne(type => User, {
|
|
74
|
+
nullable: true
|
|
75
|
+
})
|
|
76
|
+
@Field(type => User, { nullable: true })
|
|
77
|
+
updater?: User
|
|
78
|
+
|
|
79
|
+
@RelationId((geoCity: GeoCity) => geoCity.updater)
|
|
80
|
+
updaterId?: string
|
|
81
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { GeoContinent } from './geo-continent'
|
|
5
|
+
import { GeoContinentPatch, NewGeoContinent } from './geo-continent-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(GeoContinent)
|
|
8
|
+
export class GeoContinentMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => GeoContinent, { description: 'To create new GeoContinent' })
|
|
11
|
+
async createGeoContinent(
|
|
12
|
+
@Arg('geoContinent') geoContinent: NewGeoContinent,
|
|
13
|
+
@Ctx() context: ResolverContext
|
|
14
|
+
): Promise<GeoContinent> {
|
|
15
|
+
const { user, tx } = context.state
|
|
16
|
+
|
|
17
|
+
return await tx.getRepository(GeoContinent).save({
|
|
18
|
+
...geoContinent,
|
|
19
|
+
creator: user,
|
|
20
|
+
updater: user
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Directive('@transaction')
|
|
25
|
+
@Mutation(returns => GeoContinent, { description: 'To modify GeoContinent information' })
|
|
26
|
+
async updateGeoContinent(
|
|
27
|
+
@Arg('id') id: string,
|
|
28
|
+
@Arg('patch') patch: GeoContinentPatch,
|
|
29
|
+
@Ctx() context: ResolverContext
|
|
30
|
+
): Promise<GeoContinent> {
|
|
31
|
+
const { user, tx } = context.state
|
|
32
|
+
|
|
33
|
+
const repository = tx.getRepository(GeoContinent)
|
|
34
|
+
const geoContinent = await repository.findOne({
|
|
35
|
+
where: { id }
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return await repository.save({
|
|
39
|
+
...geoContinent,
|
|
40
|
+
...patch,
|
|
41
|
+
updater: user
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Directive('@transaction')
|
|
46
|
+
@Mutation(returns => [GeoContinent], { description: "To modify multiple GeoContinents' information" })
|
|
47
|
+
async updateMultipleGeoContinent(
|
|
48
|
+
@Arg('patches', type => [GeoContinentPatch]) patches: GeoContinentPatch[],
|
|
49
|
+
@Ctx() context: ResolverContext
|
|
50
|
+
): Promise<GeoContinent[]> {
|
|
51
|
+
const { user, tx } = context.state
|
|
52
|
+
|
|
53
|
+
let results = []
|
|
54
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
55
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
56
|
+
const geoContinentRepo = tx.getRepository(GeoContinent)
|
|
57
|
+
|
|
58
|
+
if (_createRecords.length > 0) {
|
|
59
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
60
|
+
const newRecord = _createRecords[i]
|
|
61
|
+
|
|
62
|
+
const result = await geoContinentRepo.save({
|
|
63
|
+
...newRecord,
|
|
64
|
+
creator: user,
|
|
65
|
+
updater: user
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
results.push({ ...result, cuFlag: '+' })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (_updateRecords.length > 0) {
|
|
73
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
74
|
+
const newRecord = _updateRecords[i]
|
|
75
|
+
const geoContinent = await geoContinentRepo.findOneBy({ id: newRecord.id })
|
|
76
|
+
|
|
77
|
+
const result = await geoContinentRepo.save({
|
|
78
|
+
...geoContinent,
|
|
79
|
+
...newRecord,
|
|
80
|
+
updater: user
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return results
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Directive('@transaction')
|
|
91
|
+
@Mutation(returns => Boolean, { description: 'To delete GeoContinent' })
|
|
92
|
+
async deleteGeoContinent(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
93
|
+
const { tx } = context.state
|
|
94
|
+
|
|
95
|
+
await tx.getRepository(GeoContinent).delete({ id })
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Directive('@transaction')
|
|
100
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple geoContinents' })
|
|
101
|
+
async deleteGeoContinents(
|
|
102
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
103
|
+
@Ctx() context: ResolverContext
|
|
104
|
+
): Promise<boolean> {
|
|
105
|
+
const { tx } = context.state
|
|
106
|
+
|
|
107
|
+
await tx.getRepository(GeoContinent).delete({
|
|
108
|
+
id: In(ids)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { GeoContinent } from './geo-continent'
|
|
7
|
+
import { GeoContinentList } from './geo-continent-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(GeoContinent)
|
|
10
|
+
export class GeoContinentQuery {
|
|
11
|
+
@Query(returns => GeoContinent, { description: 'To fetch a GeoContinent' })
|
|
12
|
+
async geoContinent(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoContinent> {
|
|
13
|
+
return await getRepository(GeoContinent).findOne({
|
|
14
|
+
where: { id }
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Query(returns => GeoContinentList, { description: 'To fetch multiple GeoContinents' })
|
|
19
|
+
async geoContinents(
|
|
20
|
+
@Args(type => ListParam) params: ListParam,
|
|
21
|
+
@Ctx() context: ResolverContext
|
|
22
|
+
): Promise<GeoContinentList> {
|
|
23
|
+
const convertedParams = convertListParams(params)
|
|
24
|
+
const [items, total] = await getRepository(GeoContinent).findAndCount(convertedParams)
|
|
25
|
+
|
|
26
|
+
return { items, total }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@FieldResolver(type => User)
|
|
30
|
+
async updater(@Root() geoContinent: GeoContinent): Promise<User> {
|
|
31
|
+
return await getRepository(User).findOneBy({ id: geoContinent.updaterId })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@FieldResolver(type => User)
|
|
35
|
+
async creator(@Root() geoContinent: GeoContinent): Promise<User> {
|
|
36
|
+
return await getRepository(User).findOneBy({ id: geoContinent.creatorId })
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
import { GeoContinent } from './geo-continent'
|
|
3
|
+
|
|
4
|
+
@InputType()
|
|
5
|
+
export class NewGeoContinent {
|
|
6
|
+
@Field()
|
|
7
|
+
name: string
|
|
8
|
+
|
|
9
|
+
@Field({ nullable: true })
|
|
10
|
+
description?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@InputType()
|
|
14
|
+
export class GeoContinentPatch {
|
|
15
|
+
@Field(type => ID, { nullable: true })
|
|
16
|
+
id?: string
|
|
17
|
+
|
|
18
|
+
@Field({ nullable: true })
|
|
19
|
+
name?: string
|
|
20
|
+
|
|
21
|
+
@Field({ nullable: true })
|
|
22
|
+
description?: string
|
|
23
|
+
|
|
24
|
+
@Field()
|
|
25
|
+
cuFlag: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@ObjectType()
|
|
29
|
+
export class GeoContinentList {
|
|
30
|
+
@Field(type => [GeoContinent])
|
|
31
|
+
items: GeoContinent[]
|
|
32
|
+
|
|
33
|
+
@Field(type => Int)
|
|
34
|
+
total: number
|
|
35
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
|
|
14
|
+
@Entity()
|
|
15
|
+
@Index('ix_geo_continent_0', (geoContinent: GeoContinent) => [geoContinent.name], { unique: true })
|
|
16
|
+
@ObjectType({ description: 'Entity for GeoContinent' })
|
|
17
|
+
export class GeoContinent {
|
|
18
|
+
@PrimaryGeneratedColumn('uuid')
|
|
19
|
+
@Field(type => ID)
|
|
20
|
+
readonly id: string
|
|
21
|
+
|
|
22
|
+
@Column()
|
|
23
|
+
@Field()
|
|
24
|
+
name: string
|
|
25
|
+
|
|
26
|
+
@Column({
|
|
27
|
+
nullable: true
|
|
28
|
+
})
|
|
29
|
+
@Field({ nullable: true })
|
|
30
|
+
description?: string
|
|
31
|
+
|
|
32
|
+
@CreateDateColumn()
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
createdAt?: Date
|
|
35
|
+
|
|
36
|
+
@UpdateDateColumn()
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
updatedAt?: Date
|
|
39
|
+
|
|
40
|
+
@ManyToOne(type => User, {
|
|
41
|
+
nullable: true
|
|
42
|
+
})
|
|
43
|
+
@Field(type => User, { nullable: true })
|
|
44
|
+
creator?: User
|
|
45
|
+
|
|
46
|
+
@RelationId((geoContinent: GeoContinent) => geoContinent.creator)
|
|
47
|
+
creatorId?: string
|
|
48
|
+
|
|
49
|
+
@ManyToOne(type => User, {
|
|
50
|
+
nullable: true
|
|
51
|
+
})
|
|
52
|
+
@Field(type => User, { nullable: true })
|
|
53
|
+
updater?: User
|
|
54
|
+
|
|
55
|
+
@RelationId((geoContinent: GeoContinent) => geoContinent.updater)
|
|
56
|
+
updaterId?: string
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GeoContinent } from './geo-continent'
|
|
2
|
+
import { GeoContinentQuery } from './geo-continent-query'
|
|
3
|
+
import { GeoContinentMutation } from './geo-continent-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [GeoContinent]
|
|
6
|
+
export const resolvers = [GeoContinentQuery, GeoContinentMutation]
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { GeoCountry } from './geo-country'
|
|
5
|
+
import { GeoCountryPatch, NewGeoCountry } from './geo-country-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(GeoCountry)
|
|
8
|
+
export class GeoCountryMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => GeoCountry, { description: 'To create new GeoCountry' })
|
|
11
|
+
async createGeoCountry(
|
|
12
|
+
@Arg('geoCountry') geoCountry: NewGeoCountry,
|
|
13
|
+
@Ctx() context: ResolverContext
|
|
14
|
+
): Promise<GeoCountry> {
|
|
15
|
+
const { user, tx } = context.state
|
|
16
|
+
|
|
17
|
+
return await tx.getRepository(GeoCountry).save({
|
|
18
|
+
...geoCountry,
|
|
19
|
+
creator: user,
|
|
20
|
+
updater: user
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Directive('@transaction')
|
|
25
|
+
@Mutation(returns => GeoCountry, { description: 'To modify GeoCountry information' })
|
|
26
|
+
async updateGeoCountry(
|
|
27
|
+
@Arg('id') id: string,
|
|
28
|
+
@Arg('patch') patch: GeoCountryPatch,
|
|
29
|
+
@Ctx() context: ResolverContext
|
|
30
|
+
): Promise<GeoCountry> {
|
|
31
|
+
const { user, tx } = context.state
|
|
32
|
+
|
|
33
|
+
const repository = tx.getRepository(GeoCountry)
|
|
34
|
+
const geoCountry = await repository.findOne({
|
|
35
|
+
where: { id }
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return await repository.save({
|
|
39
|
+
...geoCountry,
|
|
40
|
+
...patch,
|
|
41
|
+
updater: user
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Directive('@transaction')
|
|
46
|
+
@Mutation(returns => [GeoCountry], { description: "To modify multiple GeoCountries' information" })
|
|
47
|
+
async updateMultipleGeoCountry(
|
|
48
|
+
@Arg('patches', type => [GeoCountryPatch]) patches: GeoCountryPatch[],
|
|
49
|
+
@Ctx() context: ResolverContext
|
|
50
|
+
): Promise<GeoCountry[]> {
|
|
51
|
+
const { user, tx } = context.state
|
|
52
|
+
|
|
53
|
+
let results = []
|
|
54
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
55
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
56
|
+
const geoCountryRepo = tx.getRepository(GeoCountry)
|
|
57
|
+
|
|
58
|
+
if (_createRecords.length > 0) {
|
|
59
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
60
|
+
const newRecord = _createRecords[i]
|
|
61
|
+
|
|
62
|
+
const result = await geoCountryRepo.save({
|
|
63
|
+
...newRecord,
|
|
64
|
+
creator: user,
|
|
65
|
+
updater: user
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
results.push({ ...result, cuFlag: '+' })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (_updateRecords.length > 0) {
|
|
73
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
74
|
+
const newRecord = _updateRecords[i]
|
|
75
|
+
const geoCountry = await geoCountryRepo.findOneBy({ id: newRecord.id })
|
|
76
|
+
|
|
77
|
+
const result = await geoCountryRepo.save({
|
|
78
|
+
...geoCountry,
|
|
79
|
+
...newRecord,
|
|
80
|
+
updater: user
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return results
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Directive('@transaction')
|
|
91
|
+
@Mutation(returns => Boolean, { description: 'To delete GeoCountry' })
|
|
92
|
+
async deleteGeoCountry(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
93
|
+
const { tx } = context.state
|
|
94
|
+
|
|
95
|
+
await tx.getRepository(GeoCountry).delete({ id })
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Directive('@transaction')
|
|
100
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple geoCountrys' })
|
|
101
|
+
async deleteGeoCountries(
|
|
102
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
103
|
+
@Ctx() context: ResolverContext
|
|
104
|
+
): Promise<boolean> {
|
|
105
|
+
const { tx } = context.state
|
|
106
|
+
|
|
107
|
+
await tx.getRepository(GeoCountry).delete({
|
|
108
|
+
id: In(ids)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { GeoContinent } from '../geo-continent/geo-continent'
|
|
7
|
+
import { GeoCountry } from './geo-country'
|
|
8
|
+
import { GeoCountryList } from './geo-country-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(GeoCountry)
|
|
11
|
+
export class GeoCountryQuery {
|
|
12
|
+
@Query(returns => GeoCountry, { description: 'To fetch a GeoCountry' })
|
|
13
|
+
async geoCountry(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoCountry> {
|
|
14
|
+
return await getRepository(GeoCountry).findOne({
|
|
15
|
+
where: { id }
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Query(returns => GeoCountryList, { description: 'To fetch multiple GeoCountries' })
|
|
20
|
+
async geoCountries(
|
|
21
|
+
@Args(type => ListParam) params: ListParam,
|
|
22
|
+
@Ctx() context: ResolverContext
|
|
23
|
+
): Promise<GeoCountryList> {
|
|
24
|
+
const convertedParams = convertListParams(params)
|
|
25
|
+
const [items, total] = await getRepository(GeoCountry).findAndCount(convertedParams)
|
|
26
|
+
|
|
27
|
+
return { items, total }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Query(returns => GeoCountryList, { description: 'To fetch multiple GeoCountries without params' })
|
|
31
|
+
async geoCountriesWithoutParam(@Ctx() context: ResolverContext): Promise<GeoCountryList> {
|
|
32
|
+
const [items, total] = await getRepository(GeoCountry).findAndCount()
|
|
33
|
+
|
|
34
|
+
return { items, total }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@FieldResolver(type => GeoContinent)
|
|
38
|
+
async geoContinent(@Root() geoCountry: GeoCountry): Promise<GeoContinent> {
|
|
39
|
+
return await getRepository(GeoContinent).findOneBy({ id: geoCountry.geoContinentId })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@FieldResolver(type => User)
|
|
43
|
+
async updater(@Root() geoCountry: GeoCountry): Promise<User> {
|
|
44
|
+
return await getRepository(User).findOneBy({ id: geoCountry.updaterId })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@FieldResolver(type => User)
|
|
48
|
+
async creator(@Root() geoCountry: GeoCountry): Promise<User> {
|
|
49
|
+
return await getRepository(User).findOneBy({ id: geoCountry.creatorId })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
import { GeoCountry } from './geo-country'
|
|
3
|
+
|
|
4
|
+
@InputType()
|
|
5
|
+
export class NewGeoCountry {
|
|
6
|
+
@Field()
|
|
7
|
+
name: string
|
|
8
|
+
|
|
9
|
+
@Field({ nullable: true })
|
|
10
|
+
description?: string
|
|
11
|
+
|
|
12
|
+
@Field({ nullable: true })
|
|
13
|
+
isoCode?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@InputType()
|
|
17
|
+
export class GeoCountryPatch {
|
|
18
|
+
@Field(type => ID, { nullable: true })
|
|
19
|
+
id?: string
|
|
20
|
+
|
|
21
|
+
@Field({ nullable: true })
|
|
22
|
+
name?: string
|
|
23
|
+
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
description?: string
|
|
26
|
+
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
isoCode?: string
|
|
29
|
+
|
|
30
|
+
@Field()
|
|
31
|
+
cuFlag: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@ObjectType()
|
|
35
|
+
export class GeoCountryList {
|
|
36
|
+
@Field(type => [GeoCountry])
|
|
37
|
+
items: GeoCountry[]
|
|
38
|
+
|
|
39
|
+
@Field(type => Int)
|
|
40
|
+
total: number
|
|
41
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { GeoContinent } from '../geo-continent/geo-continent'
|
|
14
|
+
|
|
15
|
+
@Entity()
|
|
16
|
+
@Index('ix_geo_country_0', (geoCountry: GeoCountry) => [geoCountry.geoContinent, geoCountry.name], { unique: true })
|
|
17
|
+
@ObjectType({ description: 'Entity for GeoCountry' })
|
|
18
|
+
export class GeoCountry {
|
|
19
|
+
@PrimaryGeneratedColumn('uuid')
|
|
20
|
+
@Field(type => ID)
|
|
21
|
+
readonly id: string
|
|
22
|
+
|
|
23
|
+
@ManyToOne(type => GeoContinent)
|
|
24
|
+
@Field()
|
|
25
|
+
geoContinent: GeoContinent
|
|
26
|
+
|
|
27
|
+
@RelationId((geoCountry: GeoCountry) => geoCountry.geoContinent)
|
|
28
|
+
geoContinentId: string
|
|
29
|
+
|
|
30
|
+
@Column()
|
|
31
|
+
@Field()
|
|
32
|
+
name: string
|
|
33
|
+
|
|
34
|
+
@Column({
|
|
35
|
+
nullable: true
|
|
36
|
+
})
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
description?: string
|
|
39
|
+
|
|
40
|
+
@Column({ nullable: true })
|
|
41
|
+
@Field({ nullable: true })
|
|
42
|
+
isoCode?: string
|
|
43
|
+
|
|
44
|
+
@CreateDateColumn()
|
|
45
|
+
@Field({ nullable: true })
|
|
46
|
+
createdAt?: Date
|
|
47
|
+
|
|
48
|
+
@UpdateDateColumn()
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
updatedAt?: Date
|
|
51
|
+
|
|
52
|
+
@ManyToOne(type => User, {
|
|
53
|
+
nullable: true
|
|
54
|
+
})
|
|
55
|
+
@Field(type => User, { nullable: true })
|
|
56
|
+
creator?: User
|
|
57
|
+
|
|
58
|
+
@RelationId((geoCountry: GeoCountry) => geoCountry.creator)
|
|
59
|
+
creatorId?: string
|
|
60
|
+
|
|
61
|
+
@ManyToOne(type => User, {
|
|
62
|
+
nullable: true
|
|
63
|
+
})
|
|
64
|
+
@Field(type => User, { nullable: true })
|
|
65
|
+
updater?: User
|
|
66
|
+
|
|
67
|
+
@RelationId((geoCountry: GeoCountry) => geoCountry.updater)
|
|
68
|
+
updaterId?: string
|
|
69
|
+
}
|