@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.
Files changed (34) hide show
  1. package/dist-server/tsconfig.tsbuildinfo +1 -1
  2. package/package.json +4 -4
  3. package/server/controllers/index.ts +0 -0
  4. package/server/index.ts +5 -0
  5. package/server/middlewares/index.ts +3 -0
  6. package/server/migrations/index.ts +9 -0
  7. package/server/routes.ts +26 -0
  8. package/server/service/geo-area/geo-area-mutation.ts +107 -0
  9. package/server/service/geo-area/geo-area-query.ts +74 -0
  10. package/server/service/geo-area/geo-area-type.ts +71 -0
  11. package/server/service/geo-area/geo-area.ts +85 -0
  12. package/server/service/geo-area/index.ts +6 -0
  13. package/server/service/geo-city/geo-city-mutation.ts +110 -0
  14. package/server/service/geo-city/geo-city-query.ts +47 -0
  15. package/server/service/geo-city/geo-city-type.ts +47 -0
  16. package/server/service/geo-city/geo-city.ts +81 -0
  17. package/server/service/geo-city/index.ts +6 -0
  18. package/server/service/geo-continent/geo-continent-mutation.ts +113 -0
  19. package/server/service/geo-continent/geo-continent-query.ts +38 -0
  20. package/server/service/geo-continent/geo-continent-type.ts +35 -0
  21. package/server/service/geo-continent/geo-continent.ts +57 -0
  22. package/server/service/geo-continent/index.ts +6 -0
  23. package/server/service/geo-country/geo-country-mutation.ts +113 -0
  24. package/server/service/geo-country/geo-country-query.ts +51 -0
  25. package/server/service/geo-country/geo-country-type.ts +41 -0
  26. package/server/service/geo-country/geo-country.ts +69 -0
  27. package/server/service/geo-country/index.ts +6 -0
  28. package/server/service/geo-state/geo-state-mutation.ts +110 -0
  29. package/server/service/geo-state/geo-state-query.ts +41 -0
  30. package/server/service/geo-state/geo-state-type.ts +47 -0
  31. package/server/service/geo-state/geo-state.ts +73 -0
  32. package/server/service/geo-state/index.ts +6 -0
  33. package/server/service/index.ts +33 -0
  34. package/tsconfig.json +9 -0
@@ -0,0 +1,110 @@
1
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
+ import { In } from 'typeorm'
3
+
4
+ import { GeoState } from './geo-state'
5
+ import { GeoStatePatch, NewGeoState } from './geo-state-type'
6
+
7
+ @Resolver(GeoState)
8
+ export class GeoStateMutation {
9
+ @Directive('@transaction')
10
+ @Mutation(returns => GeoState, { description: 'To create new GeoState' })
11
+ async createGeoState(@Arg('geoState') geoState: NewGeoState, @Ctx() context: ResolverContext): Promise<GeoState> {
12
+ const { user, tx } = context.state
13
+
14
+ return await tx.getRepository(GeoState).save({
15
+ ...geoState,
16
+ creator: user,
17
+ updater: user
18
+ })
19
+ }
20
+
21
+ @Directive('@transaction')
22
+ @Mutation(returns => GeoState, { description: 'To modify GeoState information' })
23
+ async updateGeoState(
24
+ @Arg('id') id: string,
25
+ @Arg('patch') patch: GeoStatePatch,
26
+ @Ctx() context: ResolverContext
27
+ ): Promise<GeoState> {
28
+ const { user, tx } = context.state
29
+
30
+ const repository = tx.getRepository(GeoState)
31
+ const geoState = await repository.findOne({
32
+ where: { id }
33
+ })
34
+
35
+ return await repository.save({
36
+ ...geoState,
37
+ ...patch,
38
+ updater: user
39
+ })
40
+ }
41
+
42
+ @Directive('@transaction')
43
+ @Mutation(returns => [GeoState], { description: "To modify multiple GeoStates' information" })
44
+ async updateMultipleGeoState(
45
+ @Arg('patches', type => [GeoStatePatch]) patches: GeoStatePatch[],
46
+ @Ctx() context: ResolverContext
47
+ ): Promise<GeoState[]> {
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 geoStateRepo = tx.getRepository(GeoState)
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 geoStateRepo.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 geoState = await geoStateRepo.findOneBy({ id: newRecord.id })
73
+
74
+ const result = await geoStateRepo.save({
75
+ ...geoState,
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 GeoState' })
89
+ async deleteGeoState(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
90
+ const { tx } = context.state
91
+
92
+ await tx.getRepository(GeoState).delete({ id })
93
+ return true
94
+ }
95
+
96
+ @Directive('@transaction')
97
+ @Mutation(returns => Boolean, { description: 'To delete multiple geoStates' })
98
+ async deleteGeoStates(
99
+ @Arg('ids', type => [String]) ids: string[],
100
+ @Ctx() context: ResolverContext
101
+ ): Promise<boolean> {
102
+ const { tx } = context.state
103
+
104
+ await tx.getRepository(GeoState).delete({
105
+ id: In(ids)
106
+ })
107
+
108
+ return true
109
+ }
110
+ }
@@ -0,0 +1,41 @@
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'
8
+ import { GeoStateList } from './geo-state-type'
9
+
10
+ @Resolver(GeoState)
11
+ export class GeoStateQuery {
12
+ @Query(returns => GeoState, { description: 'To fetch a GeoState' })
13
+ async geoState(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<GeoState> {
14
+ return await getRepository(GeoState).findOne({
15
+ where: { id }
16
+ })
17
+ }
18
+
19
+ @Query(returns => GeoStateList, { description: 'To fetch multiple GeoStates' })
20
+ async geoStates(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<GeoStateList> {
21
+ const convertedParams = convertListParams(params)
22
+ const [items, total] = await getRepository(GeoState).findAndCount(convertedParams)
23
+
24
+ return { items, total }
25
+ }
26
+
27
+ @FieldResolver(type => GeoCountry)
28
+ async geoCountry(@Root() geoState: GeoState): Promise<GeoCountry> {
29
+ return await getRepository(GeoCountry).findOneBy({ id: geoState.geoCountryId })
30
+ }
31
+
32
+ @FieldResolver(type => User)
33
+ async updater(@Root() geoState: GeoState): Promise<User> {
34
+ return await getRepository(User).findOneBy({ id: geoState.updaterId })
35
+ }
36
+
37
+ @FieldResolver(type => User)
38
+ async creator(@Root() geoState: GeoState): Promise<User> {
39
+ return await getRepository(User).findOneBy({ id: geoState.creatorId })
40
+ }
41
+ }
@@ -0,0 +1,47 @@
1
+ import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
+ import { GeoState } from './geo-state'
3
+
4
+ @InputType()
5
+ export class NewGeoState {
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 GeoStatePatch {
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 GeoStateList {
42
+ @Field(type => [GeoState])
43
+ items: GeoState[]
44
+
45
+ @Field(type => Int)
46
+ total: number
47
+ }
@@ -0,0 +1,73 @@
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
+
15
+ @Entity()
16
+ @Index('ix_geo_state_0', (geoState: GeoState) => [geoState.geoCountry, geoState.name], { unique: true })
17
+ @ObjectType({ description: 'Entity for GeoState' })
18
+ export class GeoState {
19
+ @PrimaryGeneratedColumn('uuid')
20
+ @Field(type => ID)
21
+ readonly id: string
22
+
23
+ @ManyToOne(type => GeoCountry)
24
+ @Field()
25
+ geoCountry: GeoCountry
26
+
27
+ @RelationId((geoState: GeoState) => geoState.geoCountry)
28
+ geoCountryId: 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
+ latitude?: string
43
+
44
+ @Column({ nullable: true })
45
+ @Field({ nullable: true })
46
+ longitude?: string
47
+
48
+ @CreateDateColumn()
49
+ @Field({ nullable: true })
50
+ createdAt?: Date
51
+
52
+ @UpdateDateColumn()
53
+ @Field({ nullable: true })
54
+ updatedAt?: Date
55
+
56
+ @ManyToOne(type => User, {
57
+ nullable: true
58
+ })
59
+ @Field(type => User, { nullable: true })
60
+ creator?: User
61
+
62
+ @RelationId((geoState: GeoState) => geoState.creator)
63
+ creatorId?: string
64
+
65
+ @ManyToOne(type => User, {
66
+ nullable: true
67
+ })
68
+ @Field(type => User, { nullable: true })
69
+ updater?: User
70
+
71
+ @RelationId((geoState: GeoState) => geoState.updater)
72
+ updaterId?: string
73
+ }
@@ -0,0 +1,6 @@
1
+ import { GeoState } from './geo-state'
2
+ import { GeoStateQuery } from './geo-state-query'
3
+ import { GeoStateMutation } from './geo-state-mutation'
4
+
5
+ export const entities = [GeoState]
6
+ export const resolvers = [GeoStateQuery, GeoStateMutation]
@@ -0,0 +1,33 @@
1
+ /* EXPORT ENTITY TYPES */
2
+ export * from './geo-area/geo-area'
3
+ export * from './geo-city/geo-city'
4
+ export * from './geo-state/geo-state'
5
+ export * from './geo-country/geo-country'
6
+ export * from './geo-continent/geo-continent'
7
+
8
+ /* IMPORT ENTITIES AND RESOLVERS */
9
+ import { entities as GeoAreaEntities, resolvers as GeoAreaResolvers } from './geo-area'
10
+ import { entities as GeoCityEntities, resolvers as GeoCityResolvers } from './geo-city'
11
+ import { entities as GeoStateEntities, resolvers as GeoStateResolvers } from './geo-state'
12
+ import { entities as GeoCountryEntities, resolvers as GeoCountryResolvers } from './geo-country'
13
+ import { entities as GeoContinentEntities, resolvers as GeoContinentResolvers } from './geo-continent'
14
+
15
+ export const entities = [
16
+ /* ENTITIES */
17
+ ...GeoAreaEntities,
18
+ ...GeoCityEntities,
19
+ ...GeoStateEntities,
20
+ ...GeoCountryEntities,
21
+ ...GeoContinentEntities
22
+ ]
23
+
24
+ export const schema = {
25
+ resolverClasses: [
26
+ /* RESOLVER CLASSES */
27
+ ...GeoAreaResolvers,
28
+ ...GeoCityResolvers,
29
+ ...GeoStateResolvers,
30
+ ...GeoCountryResolvers,
31
+ ...GeoContinentResolvers
32
+ ]
33
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist-server",
5
+ "baseUrl": "./"
6
+ },
7
+ "include": ["./server/**/*"],
8
+ "exclude": ["**/*.spec.ts"]
9
+ }