@hed-hog/contact 0.0.137 → 0.0.148

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 (116) hide show
  1. package/dist/address-type/address-type.controller.d.ts +5 -5
  2. package/dist/address-type/address-type.controller.d.ts.map +1 -1
  3. package/dist/address-type/address-type.controller.js +17 -13
  4. package/dist/address-type/address-type.controller.js.map +1 -1
  5. package/dist/address-type/address-type.service.d.ts +5 -5
  6. package/dist/address-type/address-type.service.d.ts.map +1 -1
  7. package/dist/address-type/address-type.service.js +32 -4
  8. package/dist/address-type/address-type.service.js.map +1 -1
  9. package/dist/address-type/dto/create.dto.d.ts +4 -2
  10. package/dist/address-type/dto/create.dto.d.ts.map +1 -1
  11. package/dist/address-type/dto/create.dto.js +10 -1
  12. package/dist/address-type/dto/create.dto.js.map +1 -1
  13. package/dist/address-type/dto/update.dto.d.ts +3 -0
  14. package/dist/address-type/dto/update.dto.d.ts.map +1 -1
  15. package/dist/address-type/dto/update.dto.js +15 -0
  16. package/dist/address-type/dto/update.dto.js.map +1 -1
  17. package/dist/contact-type/contact-type.controller.d.ts +5 -5
  18. package/dist/contact-type/contact-type.controller.d.ts.map +1 -1
  19. package/dist/contact-type/contact-type.controller.js +16 -12
  20. package/dist/contact-type/contact-type.controller.js.map +1 -1
  21. package/dist/contact-type/contact-type.service.d.ts +5 -5
  22. package/dist/contact-type/contact-type.service.d.ts.map +1 -1
  23. package/dist/contact-type/contact-type.service.js +34 -4
  24. package/dist/contact-type/contact-type.service.js.map +1 -1
  25. package/dist/contact-type/dto/create.dto.d.ts +4 -2
  26. package/dist/contact-type/dto/create.dto.d.ts.map +1 -1
  27. package/dist/contact-type/dto/create.dto.js +10 -1
  28. package/dist/contact-type/dto/create.dto.js.map +1 -1
  29. package/dist/contact-type/dto/update.dto.d.ts +3 -0
  30. package/dist/contact-type/dto/update.dto.d.ts.map +1 -1
  31. package/dist/contact-type/dto/update.dto.js +15 -0
  32. package/dist/contact-type/dto/update.dto.js.map +1 -1
  33. package/dist/document-type/document-type.controller.d.ts +5 -5
  34. package/dist/document-type/document-type.controller.d.ts.map +1 -1
  35. package/dist/document-type/document-type.controller.js +16 -12
  36. package/dist/document-type/document-type.controller.js.map +1 -1
  37. package/dist/document-type/document-type.service.d.ts +5 -5
  38. package/dist/document-type/document-type.service.d.ts.map +1 -1
  39. package/dist/document-type/document-type.service.js +34 -4
  40. package/dist/document-type/document-type.service.js.map +1 -1
  41. package/dist/document-type/dto/create.dto.d.ts +4 -2
  42. package/dist/document-type/dto/create.dto.d.ts.map +1 -1
  43. package/dist/document-type/dto/create.dto.js +10 -1
  44. package/dist/document-type/dto/create.dto.js.map +1 -1
  45. package/dist/document-type/dto/update.dto.d.ts +3 -0
  46. package/dist/document-type/dto/update.dto.d.ts.map +1 -1
  47. package/dist/document-type/dto/update.dto.js +15 -0
  48. package/dist/document-type/dto/update.dto.js.map +1 -1
  49. package/dist/person/address/address.controller.d.ts +1 -1
  50. package/dist/person/address/address.service.d.ts +1 -1
  51. package/dist/person/contact/contact.controller.d.ts +1 -1
  52. package/dist/person/contact/contact.service.d.ts +1 -1
  53. package/dist/person/document/document.controller.d.ts +1 -1
  54. package/dist/person/document/document.service.d.ts +1 -1
  55. package/dist/person/person-metadata/person-metadata.controller.d.ts +1 -1
  56. package/dist/person/person-metadata/person-metadata.service.d.ts +1 -1
  57. package/dist/person/person-relation/person-relation.controller.d.ts +1 -1
  58. package/dist/person/person-relation/person-relation.service.d.ts +1 -1
  59. package/dist/person/person.controller.d.ts +1 -1
  60. package/dist/person/person.controller.js +1 -1
  61. package/dist/person/person.controller.js.map +1 -1
  62. package/dist/person/person.module.d.ts.map +1 -1
  63. package/dist/person/person.module.js +1 -29
  64. package/dist/person/person.module.js.map +1 -1
  65. package/dist/person/person.service.d.ts +4 -4
  66. package/dist/person/person.service.d.ts.map +1 -1
  67. package/dist/person/person.service.js +21 -6
  68. package/dist/person/person.service.js.map +1 -1
  69. package/dist/person-relation-type/person-relation-type.controller.d.ts +1 -1
  70. package/dist/person-relation-type/person-relation-type.service.d.ts +1 -1
  71. package/package.json +4 -4
  72. package/src/address-type/address-type.controller.ts +8 -8
  73. package/src/address-type/address-type.service.ts +55 -8
  74. package/src/address-type/dto/create.dto.ts +12 -3
  75. package/src/address-type/dto/update.dto.ts +6 -1
  76. package/src/contact-type/contact-type.controller.ts +8 -8
  77. package/src/contact-type/contact-type.service.ts +57 -8
  78. package/src/contact-type/dto/create.dto.ts +12 -3
  79. package/src/contact-type/dto/update.dto.ts +6 -1
  80. package/src/document-type/document-type.controller.ts +8 -8
  81. package/src/document-type/document-type.service.ts +56 -8
  82. package/src/document-type/dto/create.dto.ts +12 -3
  83. package/src/document-type/dto/update.dto.ts +6 -1
  84. package/src/language/en.json +7 -0
  85. package/src/language/pt.json +7 -0
  86. package/src/person/person.controller.ts +1 -1
  87. package/src/person/person.module.ts +1 -29
  88. package/src/person/person.service.ts +30 -6
  89. package/src/person/address/address.controller.ts +0 -67
  90. package/src/person/address/address.service.ts +0 -91
  91. package/src/person/address/dto/create.dto.ts +0 -30
  92. package/src/person/address/dto/update.dto.ts +0 -4
  93. package/src/person/contact/contact.controller.ts +0 -67
  94. package/src/person/contact/contact.service.ts +0 -83
  95. package/src/person/contact/dto/create.dto.ts +0 -14
  96. package/src/person/contact/dto/update.dto.ts +0 -4
  97. package/src/person/document/document.controller.ts +0 -67
  98. package/src/person/document/document.service.ts +0 -83
  99. package/src/person/document/dto/create.dto.ts +0 -10
  100. package/src/person/document/dto/update.dto.ts +0 -4
  101. package/src/person/person-company/dto/create.dto.ts +0 -14
  102. package/src/person/person-company/dto/update.dto.ts +0 -4
  103. package/src/person/person-company/person-company.controller.ts +0 -45
  104. package/src/person/person-company/person-company.service.ts +0 -32
  105. package/src/person/person-individual/dto/create.dto.ts +0 -20
  106. package/src/person/person-individual/dto/update.dto.ts +0 -4
  107. package/src/person/person-individual/person-individual.controller.ts +0 -45
  108. package/src/person/person-individual/person-individual.service.ts +0 -36
  109. package/src/person/person-metadata/dto/create.dto.ts +0 -9
  110. package/src/person/person-metadata/dto/update.dto.ts +0 -4
  111. package/src/person/person-metadata/person-metadata.controller.ts +0 -67
  112. package/src/person/person-metadata/person-metadata.service.ts +0 -83
  113. package/src/person/person-relation/dto/create.dto.ts +0 -10
  114. package/src/person/person-relation/dto/update.dto.ts +0 -4
  115. package/src/person/person-relation/person-relation.controller.ts +0 -67
  116. package/src/person/person-relation/person-relation.service.ts +0 -91
@@ -18,7 +18,7 @@ export declare class PersonRelationTypeService {
18
18
  pageSize: number;
19
19
  prev: number;
20
20
  next: number;
21
- data: any;
21
+ data: any[];
22
22
  }>;
23
23
  get(id: number): Promise<any>;
24
24
  create(data: CreateDTO): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hed-hog/contact",
3
- "version": "0.0.137",
3
+ "version": "0.0.148",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "dependencies": {
@@ -10,10 +10,10 @@
10
10
  "@nestjs/jwt": "^11",
11
11
  "@nestjs/mapped-types": "*",
12
12
  "@hed-hog/api-mail": "0.0.7",
13
+ "@hed-hog/api-locale": "0.0.11",
14
+ "@hed-hog/core": "0.0.145",
13
15
  "@hed-hog/api-prisma": "0.0.4",
14
- "@hed-hog/api-locale": "0.0.10",
15
- "@hed-hog/core": "0.0.137",
16
- "@hed-hog/api-pagination": "0.0.4",
16
+ "@hed-hog/api-pagination": "0.0.5",
17
17
  "@hed-hog/api": "0.0.3"
18
18
  },
19
19
  "exports": {
@@ -31,25 +31,25 @@ export class PersonAddressTypeController {
31
31
  }
32
32
 
33
33
  @Get(':id')
34
- async get(@Param('id', ParseIntPipe) id: number) {
35
- return this.personAddressTypeService.get(id);
34
+ async get(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
35
+ return this.personAddressTypeService.get(id, locale);
36
36
  }
37
37
 
38
38
  @Post()
39
- async create(@Body() data: CreateDTO) {
40
- return this.personAddressTypeService.create(data);
39
+ async create(@Locale() locale: string, @Body() data: CreateDTO) {
40
+ return this.personAddressTypeService.create(data, locale);
41
41
  }
42
42
 
43
43
  @Patch(':id')
44
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
44
+ async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO, @Locale() locale: string) {
45
45
  return this.personAddressTypeService.update({
46
46
  id,
47
47
  data
48
- });
48
+ }, locale);
49
49
  }
50
50
 
51
51
  @Delete()
52
- async delete(@Body() data: DeleteDTO) {
53
- return this.personAddressTypeService.delete(data);
52
+ async delete(@Body() data: DeleteDTO, @Locale() locale: string) {
53
+ return this.personAddressTypeService.delete(data, locale);
54
54
  }
55
55
  }
@@ -3,10 +3,11 @@ import { LocaleService, getLocaleText } from '@hed-hog/api-locale';
3
3
  import { PaginationDTO } from '@hed-hog/api-pagination';
4
4
  import { PrismaService } from '@hed-hog/api-prisma';
5
5
  import {
6
- BadRequestException,
7
- Inject,
8
- Injectable,
9
- forwardRef
6
+ BadRequestException,
7
+ Inject,
8
+ Injectable,
9
+ NotFoundException,
10
+ forwardRef
10
11
  } from '@nestjs/common';
11
12
  import { CreateDTO } from './dto/create.dto';
12
13
  import { UpdateDTO } from './dto/update.dto';
@@ -31,11 +32,25 @@ export class PersonAddressTypeService {
31
32
  );
32
33
  }
33
34
 
34
- async get(id: number) {
35
+ async get(id: number, locale: string) {
36
+ const addressType = await this.prismaService.address_type.findUnique({ where: { id }});
37
+
38
+ if (!addressType) {
39
+ throw new NotFoundException(
40
+ getLocaleText('addressTypeNotFound', locale, `Address Type with ID ${id} not found`).replace('{{item}}', 'Address Type')
41
+ );
42
+ }
43
+
35
44
  return this.localeService.getModelWithLocale(this.modelName, id);
36
45
  }
37
46
 
38
- async create(data: CreateDTO) {
47
+ async create(data: CreateDTO, locale: string) {
48
+ if (!data.locale || Object.keys(data.locale).length === 0) {
49
+ throw new BadRequestException(
50
+ getLocaleText('localeRequired', locale, 'At least one locale is required')
51
+ );
52
+ }
53
+
39
54
  return this.localeService.createModelWithLocale(
40
55
  this.modelName,
41
56
  this.foreignKey,
@@ -43,7 +58,23 @@ export class PersonAddressTypeService {
43
58
  );
44
59
  }
45
60
 
46
- async update({ id, data }: { id: number; data: UpdateDTO }) {
61
+ async update({ id, data }: { id: number; data: UpdateDTO }, locale: string) {
62
+ const addressTypeExists = await this.prismaService.address_type.findUnique({
63
+ where: { id }
64
+ });
65
+
66
+ if (!addressTypeExists) {
67
+ throw new NotFoundException(
68
+ getLocaleText('addressTypeNotFound', locale, `Address Type with ID ${id} not found`).replace('{{item}}', 'Address Type')
69
+ );
70
+ }
71
+
72
+ if (data.locale && Object.keys(data.locale).length === 0) {
73
+ throw new BadRequestException(
74
+ getLocaleText('localeRequired', locale, 'At least one locale is required')
75
+ );
76
+ }
77
+
47
78
  return this.localeService.updateModelWithLocale(
48
79
  this.modelName,
49
80
  this.foreignKey,
@@ -52,7 +83,7 @@ export class PersonAddressTypeService {
52
83
  );
53
84
  }
54
85
 
55
- async delete({ ids }: DeleteDTO, locale: string = 'en') {
86
+ async delete({ ids }: DeleteDTO, locale: string) {
56
87
  if (ids == undefined || ids == null) {
57
88
  throw new BadRequestException(
58
89
  getLocaleText(
@@ -63,6 +94,22 @@ export class PersonAddressTypeService {
63
94
  );
64
95
  }
65
96
 
97
+ const existingAddressTypes = await this.prismaService.address_type.findMany({
98
+ where: {
99
+ id: {
100
+ in: ids,
101
+ },
102
+ },
103
+ });
104
+
105
+ if (existingAddressTypes.length !== ids.length) {
106
+ const existingIds = existingAddressTypes.map((item) => item.id);
107
+ const missingIds = ids.filter((id) => !existingIds.includes(id));
108
+ throw new NotFoundException(
109
+ getLocaleText('addressTypesNotFound', locale, `Address Types with IDs ${missingIds.join(', ')} not found`).replace('{{items}}', 'Address Types')
110
+ );
111
+ }
112
+
66
113
  return this.prismaService.address_type.deleteMany({
67
114
  where: {
68
115
  id: {
@@ -1,10 +1,19 @@
1
- import { getLocaleText, WithLocaleDTO } from '@hed-hog/api-locale';
2
- import { IsString } from 'class-validator';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsNotEmpty, IsObject, IsString } from 'class-validator';
3
3
 
4
- export class CreateDTO extends WithLocaleDTO {
4
+ export class CreateDTO {
5
5
  @IsString({
6
6
  message: (args) =>
7
7
  getLocaleText('validation.codeMustBeString', args.value),
8
8
  })
9
9
  code: string;
10
+
11
+ @IsObject({
12
+ message: (args) =>
13
+ getLocaleText('validation.localeMustBeObject', args.value),
14
+ })
15
+ @IsNotEmpty({
16
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
17
+ })
18
+ locale: Record<string, { name: string }>;
10
19
  }
@@ -1,4 +1,9 @@
1
1
  import { PartialType } from '@nestjs/mapped-types';
2
+ import { IsObject, IsOptional } from 'class-validator';
2
3
  import { CreateDTO } from './create.dto';
3
4
 
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
5
+ export class UpdateDTO extends PartialType(CreateDTO) {
6
+ @IsOptional()
7
+ @IsObject()
8
+ locale?: Record<string, { name: string }>;
9
+ }
@@ -31,25 +31,25 @@ export class PersonContactTypeController {
31
31
  }
32
32
 
33
33
  @Get(':id')
34
- async get(@Param('id', ParseIntPipe) id: number) {
35
- return this.personContactTypeService.get(id);
34
+ async get(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
35
+ return this.personContactTypeService.get(id, locale);
36
36
  }
37
37
 
38
38
  @Post()
39
- async create(@Body() data: CreateDTO) {
40
- return this.personContactTypeService.create(data);
39
+ async create(@Body() data: CreateDTO, @Locale() locale: string) {
40
+ return this.personContactTypeService.create(data, locale);
41
41
  }
42
42
 
43
43
  @Patch(':id')
44
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
44
+ async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO, @Locale() locale: string) {
45
45
  return this.personContactTypeService.update({
46
46
  id,
47
47
  data
48
- });
48
+ }, locale);
49
49
  }
50
50
 
51
51
  @Delete()
52
- async delete(@Body() data: DeleteDTO) {
53
- return this.personContactTypeService.delete(data);
52
+ async delete(@Body() data: DeleteDTO, @Locale() locale: string) {
53
+ return this.personContactTypeService.delete(data, locale);
54
54
  }
55
55
  }
@@ -3,10 +3,11 @@ import { LocaleService, getLocaleText } from '@hed-hog/api-locale';
3
3
  import { PaginationDTO } from '@hed-hog/api-pagination';
4
4
  import { PrismaService } from '@hed-hog/api-prisma';
5
5
  import {
6
- BadRequestException,
7
- Inject,
8
- Injectable,
9
- forwardRef
6
+ BadRequestException,
7
+ Inject,
8
+ Injectable,
9
+ NotFoundException,
10
+ forwardRef
10
11
  } from '@nestjs/common';
11
12
  import { CreateDTO } from './dto/create.dto';
12
13
  import { UpdateDTO } from './dto/update.dto';
@@ -31,11 +32,27 @@ export class PersonContactTypeService {
31
32
  );
32
33
  }
33
34
 
34
- async get(id: number) {
35
+ async get(id: number, locale: string) {
36
+ const contactType = await this.prismaService.contact_type.findUnique({
37
+ where: { id }
38
+ });
39
+
40
+ if (!contactType) {
41
+ throw new NotFoundException(
42
+ getLocaleText('contactTypeNotFound', locale, `Contact Type with ID ${id} not found`).replace('{{item}}', 'Contact Type')
43
+ );
44
+ }
45
+
35
46
  return this.localeService.getModelWithLocale(this.modelName, id);
36
47
  }
37
48
 
38
- async create(data: CreateDTO) {
49
+ async create(data: CreateDTO, locale: string) {
50
+ if (!data.locale || Object.keys(data.locale).length === 0) {
51
+ throw new BadRequestException(
52
+ getLocaleText('localeRequired', locale, 'At least one locale is required')
53
+ );
54
+ }
55
+
39
56
  return this.localeService.createModelWithLocale(
40
57
  this.modelName,
41
58
  this.foreignKey,
@@ -43,7 +60,23 @@ export class PersonContactTypeService {
43
60
  );
44
61
  }
45
62
 
46
- async update({ id, data }: { id: number; data: UpdateDTO }) {
63
+ async update({ id, data }: { id: number; data: UpdateDTO }, locale: string) {
64
+ const contactTypeExists = await this.prismaService.contact_type.findUnique({
65
+ where: { id }
66
+ });
67
+
68
+ if (!contactTypeExists) {
69
+ throw new NotFoundException(
70
+ getLocaleText('contactTypeNotFound', locale, `Contact Type with ID ${id} not found`).replace('{{item}}', 'Contact Type')
71
+ );
72
+ }
73
+
74
+ if (data.locale && Object.keys(data.locale).length === 0) {
75
+ throw new BadRequestException(
76
+ getLocaleText('localeRequired', locale, 'At least one locale is required')
77
+ );
78
+ }
79
+
47
80
  return this.localeService.updateModelWithLocale(
48
81
  this.modelName,
49
82
  this.foreignKey,
@@ -52,7 +85,7 @@ export class PersonContactTypeService {
52
85
  );
53
86
  }
54
87
 
55
- async delete({ ids }: DeleteDTO, locale: string = 'en') {
88
+ async delete({ ids }: DeleteDTO, locale: string) {
56
89
  if (ids == undefined || ids == null) {
57
90
  throw new BadRequestException(
58
91
  getLocaleText(
@@ -63,6 +96,22 @@ export class PersonContactTypeService {
63
96
  );
64
97
  }
65
98
 
99
+ const existingContactTypes = await this.prismaService.contact_type.findMany({
100
+ where: {
101
+ id: {
102
+ in: ids,
103
+ },
104
+ },
105
+ });
106
+
107
+ if (existingContactTypes.length !== ids.length) {
108
+ const existingIds = existingContactTypes.map((item) => item.id);
109
+ const missingIds = ids.filter((id) => !existingIds.includes(id));
110
+ throw new NotFoundException(
111
+ getLocaleText('contactTypesNotFound', locale, `Contact Types with IDs ${missingIds.join(', ')} not found`).replace('{{items}}', 'Contact Types')
112
+ );
113
+ }
114
+
66
115
  return this.prismaService.contact_type.deleteMany({
67
116
  where: {
68
117
  id: {
@@ -1,10 +1,19 @@
1
- import { getLocaleText, WithLocaleDTO } from '@hed-hog/api-locale';
2
- import { IsString } from 'class-validator';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsNotEmpty, IsObject, IsString } from 'class-validator';
3
3
 
4
- export class CreateDTO extends WithLocaleDTO {
4
+ export class CreateDTO {
5
5
  @IsString({
6
6
  message: (args) =>
7
7
  getLocaleText('validation.codeMustBeString', args.value),
8
8
  })
9
9
  code: string;
10
+
11
+ @IsObject({
12
+ message: (args) =>
13
+ getLocaleText('validation.localeMustBeObject', args.value),
14
+ })
15
+ @IsNotEmpty({
16
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
17
+ })
18
+ locale: Record<string, { name: string }>;
10
19
  }
@@ -1,4 +1,9 @@
1
1
  import { PartialType } from '@nestjs/mapped-types';
2
+ import { IsObject, IsOptional } from 'class-validator';
2
3
  import { CreateDTO } from './create.dto';
3
4
 
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
5
+ export class UpdateDTO extends PartialType(CreateDTO) {
6
+ @IsOptional()
7
+ @IsObject()
8
+ locale?: Record<string, { name: string }>;
9
+ }
@@ -31,25 +31,25 @@ export class PersonDocumentTypeController {
31
31
  }
32
32
 
33
33
  @Get(':id')
34
- async get(@Param('id', ParseIntPipe) id: number) {
35
- return this.personDocumentTypeService.get(id);
34
+ async get(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
35
+ return this.personDocumentTypeService.get(id, locale);
36
36
  }
37
37
 
38
38
  @Post()
39
- async create(@Body() data: CreateDTO) {
40
- return this.personDocumentTypeService.create(data);
39
+ async create(@Body() data: CreateDTO, @Locale() locale: string) {
40
+ return this.personDocumentTypeService.create(data, locale);
41
41
  }
42
42
 
43
43
  @Patch(':id')
44
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
44
+ async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO, @Locale() locale: string) {
45
45
  return this.personDocumentTypeService.update({
46
46
  id,
47
47
  data
48
- });
48
+ }, locale);
49
49
  }
50
50
 
51
51
  @Delete()
52
- async delete(@Body() data: DeleteDTO) {
53
- return this.personDocumentTypeService.delete(data);
52
+ async delete(@Body() data: DeleteDTO, @Locale() locale: string) {
53
+ return this.personDocumentTypeService.delete(data, locale);
54
54
  }
55
55
  }
@@ -3,10 +3,11 @@ import { LocaleService, getLocaleText } from '@hed-hog/api-locale';
3
3
  import { PaginationDTO } from '@hed-hog/api-pagination';
4
4
  import { PrismaService } from '@hed-hog/api-prisma';
5
5
  import {
6
- BadRequestException,
7
- Inject,
8
- Injectable,
9
- forwardRef
6
+ BadRequestException,
7
+ Inject,
8
+ Injectable,
9
+ NotFoundException,
10
+ forwardRef
10
11
  } from '@nestjs/common';
11
12
  import { CreateDTO } from './dto/create.dto';
12
13
  import { UpdateDTO } from './dto/update.dto';
@@ -31,11 +32,27 @@ export class PersonDocumentTypeService {
31
32
  );
32
33
  }
33
34
 
34
- async get(id: number) {
35
+ async get(id: number, locale: string) {
36
+ const documentType = await this.prismaService.document_type.findUnique({
37
+ where: { id }
38
+ });
39
+
40
+ if (!documentType) {
41
+ throw new NotFoundException(
42
+ getLocaleText('documentTypeNotFound', locale, `Document Type with ID ${id} not found`).replace('{{item}}', 'Document Type')
43
+ );
44
+ }
45
+
35
46
  return this.localeService.getModelWithLocale(this.modelName, id);
36
47
  }
37
48
 
38
- async create(data: CreateDTO) {
49
+ async create(data: CreateDTO, locale: string) {
50
+ if (!data.locale || Object.keys(data.locale).length === 0) {
51
+ throw new BadRequestException(
52
+ getLocaleText('localeRequired', locale, 'At least one locale is required')
53
+ );
54
+ }
55
+
39
56
  return this.localeService.createModelWithLocale(
40
57
  this.modelName,
41
58
  this.foreignKey,
@@ -43,7 +60,22 @@ export class PersonDocumentTypeService {
43
60
  );
44
61
  }
45
62
 
46
- async update({ id, data }: { id: number; data: UpdateDTO }) {
63
+ async update({ id, data }: { id: number; data: UpdateDTO }, locale: string) {
64
+ const documentTypeExists = await this.prismaService.document_type.findUnique({
65
+ where: { id }
66
+ });
67
+
68
+ if (!documentTypeExists) {
69
+ throw new NotFoundException(
70
+ getLocaleText('documentTypeNotFound', locale, `Document Type with ID ${id} not found`).replace('{{item}}', 'Document Type')
71
+ );
72
+ }
73
+
74
+ if (data.locale && Object.keys(data.locale).length === 0) {
75
+ throw new BadRequestException(
76
+ getLocaleText('localeRequired', locale, 'At least one locale is required')
77
+ );
78
+ }
47
79
  return this.localeService.updateModelWithLocale(
48
80
  this.modelName,
49
81
  this.foreignKey,
@@ -52,7 +84,7 @@ export class PersonDocumentTypeService {
52
84
  );
53
85
  }
54
86
 
55
- async delete({ ids }: DeleteDTO, locale: string = 'en') {
87
+ async delete({ ids }: DeleteDTO, locale: string) {
56
88
  if (ids == undefined || ids == null) {
57
89
  throw new BadRequestException(
58
90
  getLocaleText(
@@ -63,6 +95,22 @@ export class PersonDocumentTypeService {
63
95
  );
64
96
  }
65
97
 
98
+ const existingDocumentTypes = await this.prismaService.document_type.findMany({
99
+ where: {
100
+ id: {
101
+ in: ids,
102
+ },
103
+ },
104
+ });
105
+
106
+ if (existingDocumentTypes.length !== ids.length) {
107
+ const existingIds = existingDocumentTypes.map((item) => item.id);
108
+ const missingIds = ids.filter((id) => !existingIds.includes(id));
109
+ throw new NotFoundException(
110
+ getLocaleText('documentTypesNotFound', locale, `Document Types with IDs ${missingIds.join(', ')} not found`).replace('{{items}}', 'Document Types')
111
+ );
112
+ }
113
+
66
114
  return this.prismaService.document_type.deleteMany({
67
115
  where: {
68
116
  id: {
@@ -1,7 +1,7 @@
1
- import { getLocaleText, WithLocaleDTO } from '@hed-hog/api-locale';
2
- import { IsBoolean, IsString } from 'class-validator';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsBoolean, IsNotEmpty, IsObject, IsString } from 'class-validator';
3
3
 
4
- export class CreateDTO extends WithLocaleDTO {
4
+ export class CreateDTO {
5
5
  @IsString({
6
6
  message: (args) =>
7
7
  getLocaleText('validation.codeMustBeString', args.value),
@@ -16,4 +16,13 @@ export class CreateDTO extends WithLocaleDTO {
16
16
 
17
17
  @IsBoolean()
18
18
  is_unique: boolean;
19
+
20
+ @IsObject({
21
+ message: (args) =>
22
+ getLocaleText('validation.localeMustBeObject', args.value),
23
+ })
24
+ @IsNotEmpty({
25
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
26
+ })
27
+ locale: Record<string, { name: string }>;
19
28
  }
@@ -1,4 +1,9 @@
1
1
  import { PartialType } from '@nestjs/mapped-types';
2
+ import { IsObject, IsOptional } from 'class-validator';
2
3
  import { CreateDTO } from './create.dto';
3
4
 
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
5
+ export class UpdateDTO extends PartialType(CreateDTO) {
6
+ @IsOptional()
7
+ @IsObject()
8
+ locale?: Record<string, { name: string }>;
9
+ }
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "deleteItemsRequired": "You must select at least one item to delete.",
3
+ "localeRequired": "Name is required.",
3
4
  "personNotFound": "Person not found",
5
+ "addressTypeNotFound": "Address Type not found",
6
+ "contactTypeNotFound": "Contact Type not found",
7
+ "documentTypeNotFound": "Document Type not found",
8
+ "addressTypesNotFound": "Address Types not found",
9
+ "contactTypesNotFound": "Contact Types not found",
10
+ "documentTypesNotFound": "Document Types not found",
4
11
  "moreThanOnePrimaryContact": "More than one contact of the same type cannot be marked as primary.",
5
12
  "moreThanOnePrimaryAddress": "More than one address of the same type cannot be marked as primary.",
6
13
  "moreThanOnePrimaryDocument": "More than one document of the same type cannot be marked as primary.",
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "deleteItemsRequired": "Você deve selecionar pelo menos um item para excluir.",
3
+ "localeRequired": "Nome é obrigatório.",
3
4
  "personNotFound": "Pessoa não encontrada",
5
+ "addressTypeNotFound": "Tipo de Endereço não encontrado",
6
+ "contactTypeNotFound": "Tipo de Contato não encontrado",
7
+ "documentTypeNotFound": "Tipo de Documento não encontrado",
8
+ "addressTypesNotFound": "Tipos de Endereço não encontrados",
9
+ "contactTypesNotFound": "Tipos de Contato não encontrados",
10
+ "documentTypesNotFound": "Tipos de Documento não encontrados",
4
11
  "moreThanOnePrimaryContact": "Não é permitido mais de um contato do mesmo tipo marcado como principal.",
5
12
  "moreThanOnePrimaryAddress": "Não é permitido mais de um endereço do mesmo tipo marcado como principal.",
6
13
  "moreThanOnePrimaryDocument": "Não é permitido mais de um documento do mesmo tipo marcado como principal.",
@@ -38,7 +38,7 @@ export class PersonController {
38
38
 
39
39
  @Get(':id')
40
40
  async get(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
41
- return this.personService.get(id);
41
+ return this.personService.get(locale, id);
42
42
  }
43
43
 
44
44
  @Post()
@@ -1,21 +1,7 @@
1
- import { CoreModule } from "@hed-hog/core";
2
1
  import { PaginationModule } from "@hed-hog/api-pagination";
3
2
  import { PrismaModule } from "@hed-hog/api-prisma";
3
+ import { CoreModule } from "@hed-hog/core";
4
4
  import { forwardRef, Module } from "@nestjs/common";
5
- import { PersonAddressController } from "./address/address.controller";
6
- import { PersonAddressService } from "./address/address.service";
7
- import { PersonContactController } from "./contact/contact.controller";
8
- import { PersonContactService } from "./contact/contact.service";
9
- import { PersonDocumentController } from "./document/document.controller";
10
- import { PersonDocumentService } from "./document/document.service";
11
- import { PersonCompanyController } from "./person-company/person-company.controller";
12
- import { PersonCompanyService } from "./person-company/person-company.service";
13
- import { PersonIndividualController } from "./person-individual/person-individual.controller";
14
- import { PersonIndividualService } from "./person-individual/person-individual.service";
15
- import { PersonMetadataController } from "./person-metadata/person-metadata.controller";
16
- import { PersonMetadataService } from "./person-metadata/person-metadata.service";
17
- import { PersonRelationController } from "./person-relation/person-relation.controller";
18
- import { PersonRelationService } from "./person-relation/person-relation.service";
19
5
  import { PersonController } from "./person.controller";
20
6
  import { PersonService } from "./person.service";
21
7
  @Module({
@@ -25,23 +11,9 @@ import { PersonService } from "./person.service";
25
11
  forwardRef(() => PaginationModule),
26
12
  ],
27
13
  controllers: [
28
- PersonMetadataController,
29
- PersonAddressController,
30
- PersonContactController,
31
- PersonDocumentController,
32
- PersonRelationController,
33
- PersonIndividualController,
34
- PersonCompanyController,
35
14
  PersonController,
36
15
  ],
37
16
  providers: [
38
- PersonMetadataService,
39
- PersonAddressService,
40
- PersonContactService,
41
- PersonDocumentService,
42
- PersonRelationService,
43
- PersonIndividualService,
44
- PersonCompanyService,
45
17
  PersonService,
46
18
  ],
47
19
  exports: [forwardRef(() => PersonService)],