@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
@@ -74,10 +74,13 @@ export class PersonService {
74
74
  );
75
75
  }
76
76
 
77
- async get(id: number) {
78
- return this.prismaService.person.findUnique({
79
- where: { id: id },
80
- });
77
+ async get(locale: string, id: number) {
78
+ const person = await this.prismaService.person.findUnique({ where: { id } });
79
+ if (!person) {
80
+ throw new BadRequestException(getLocaleText('personNotFound', locale, `Person with ID ${id} not found`));
81
+ }
82
+
83
+ return person
81
84
  }
82
85
 
83
86
  async create(data: CreateDTO) {
@@ -86,7 +89,12 @@ export class PersonService {
86
89
  });
87
90
  }
88
91
 
89
- async update(id: number, data: any, locale: string = 'en') {
92
+ async update(id: number, data: any, locale: string) {
93
+ const person = await this.prismaService.person.findUnique({ where: { id } });
94
+ if (!person) {
95
+ throw new BadRequestException(getLocaleText('personNotFound', locale, `Person with ID ${id} not found`));
96
+ }
97
+
90
98
  const incomingContacts = data.contacts || [];
91
99
  const incomingAddresses = data.addresses || [];
92
100
  const incomingDocuments = data.documents || [];
@@ -192,13 +200,29 @@ export class PersonService {
192
200
  });
193
201
  }
194
202
 
195
- async delete({ ids }: DeleteDTO, locale: string = 'en') {
203
+ async delete({ ids }: DeleteDTO, locale: string) {
196
204
  if (ids == undefined || ids == null) {
197
205
  throw new BadRequestException(
198
206
  getLocaleText('deleteItemsRequired', locale, 'You must select at least one item to delete.'),
199
207
  );
200
208
  }
201
209
 
210
+ const existing = await this.prismaService.person.findMany({
211
+ where: { id: { in: ids } },
212
+ select: { id: true },
213
+ });
214
+ const existingIds = existing.map(p => p.id);
215
+ const missingIds = ids.filter(id => !existingIds.includes(id));
216
+ if (missingIds.length > 0) {
217
+ throw new BadRequestException(
218
+ getLocaleText(
219
+ 'personNotFound',
220
+ locale,
221
+ `Person(s) with ID(s) ${missingIds.join(', ')} not found.`
222
+ )
223
+ );
224
+ }
225
+
202
226
  return this.prismaService.$transaction([
203
227
  this.prismaService.contact.deleteMany({ where: { person_id: { in: ids } } }),
204
228
  this.prismaService.address.deleteMany({ where: { person_id: { in: ids } } }),
@@ -1,67 +0,0 @@
1
- import { DeleteDTO, Role } from '@hed-hog/api';
2
- import { Pagination } from '@hed-hog/api-pagination';
3
- import {
4
- Body,
5
- Controller,
6
- Delete,
7
- Get,
8
- Inject,
9
- Param,
10
- ParseIntPipe,
11
- Patch,
12
- Post,
13
- forwardRef
14
- } from '@nestjs/common';
15
- import { PersonAddressService } from './address.service';
16
- import { CreateDTO } from './dto/create.dto';
17
- import { UpdateDTO } from './dto/update.dto';
18
-
19
- @Role()
20
- @Controller('person/:personId/person-address')
21
- export class PersonAddressController {
22
- constructor(
23
- @Inject(forwardRef(() => PersonAddressService))
24
- private readonly personAddressService: PersonAddressService
25
- ) {}
26
-
27
- @Post()
28
- create(
29
- @Param('personId', ParseIntPipe) personId: number,
30
- @Body() data: CreateDTO
31
- ) {
32
- return this.personAddressService.create(personId, data);
33
- }
34
-
35
- @Get()
36
- list(
37
- @Param('personId', ParseIntPipe) personId: number,
38
- @Pagination() paginationParams
39
- ) {
40
- return this.personAddressService.list(paginationParams, personId);
41
- }
42
-
43
- @Get(':id')
44
- get(
45
- @Param('personId', ParseIntPipe) personId: number,
46
- @Param('id', ParseIntPipe) id: number
47
- ) {
48
- return this.personAddressService.get(personId, id);
49
- }
50
-
51
- @Patch(':id')
52
- update(
53
- @Param('personId', ParseIntPipe) personId: number,
54
- @Param('id', ParseIntPipe) id: number,
55
- @Body() data: UpdateDTO
56
- ) {
57
- return this.personAddressService.update(personId, id, data);
58
- }
59
-
60
- @Delete()
61
- delete(
62
- @Param('personId', ParseIntPipe) personId: number,
63
- @Body() { ids }: DeleteDTO
64
- ) {
65
- return this.personAddressService.delete(personId, { ids });
66
- }
67
- }
@@ -1,91 +0,0 @@
1
- import { DeleteDTO } from '@hed-hog/api';
2
- import { getLocaleText } from '@hed-hog/api-locale';
3
- import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
4
- import { PrismaService } from '@hed-hog/api-prisma';
5
- import {
6
- BadRequestException,
7
- Injectable
8
- } from '@nestjs/common';
9
- import { CreateDTO } from './dto/create.dto';
10
- import { UpdateDTO } from './dto/update.dto';
11
-
12
- @Injectable()
13
- export class PersonAddressService {
14
- constructor(
15
- private readonly prismaService: PrismaService,
16
- private readonly paginationService: PaginationService
17
- ) {}
18
-
19
- async create(personId: number, data: CreateDTO) {
20
- const { address_type_id, ...addressData } = data;
21
- return this.prismaService.address.create({
22
- data: {
23
- ...addressData,
24
- line2: addressData.line2 || '',
25
- person: {
26
- connect: { id: personId }
27
- },
28
- address_type: {
29
- connect: { id: address_type_id }
30
- }
31
- }
32
- });
33
- }
34
-
35
- async get(personId: number, id: number) {
36
- return this.prismaService.address.findFirst({
37
- where: {
38
- person_id: personId,
39
- id: id
40
- }
41
- });
42
- }
43
-
44
- async list(paginationParams: PaginationDTO, personId?: number) {
45
- const where: any = {};
46
- if (personId !== undefined) where.person_id = personId;
47
-
48
- return this.paginationService.paginate(
49
- this.prismaService.address,
50
- {
51
- fields:
52
- 'is_primary,country_code,state,city,postal_code,line1,line2',
53
- ...paginationParams
54
- },
55
- {
56
- where
57
- }
58
- );
59
- }
60
-
61
- async update(personId: number, id: number, data: UpdateDTO) {
62
- return this.prismaService.address.updateMany({
63
- where: {
64
- person_id: personId,
65
- id: id
66
- },
67
- data
68
- });
69
- }
70
-
71
- async delete(personId: number, { ids }: DeleteDTO, locale: string = 'en') {
72
- if (ids == undefined || ids == null) {
73
- throw new BadRequestException(
74
- getLocaleText(
75
- 'deleteItemsRequired',
76
- locale,
77
- 'You must select at least one item to delete.',
78
- ),
79
- );
80
- }
81
-
82
- return this.prismaService.address.deleteMany({
83
- where: {
84
- person_id: personId,
85
- id: {
86
- in: ids
87
- }
88
- }
89
- });
90
- }
91
- }
@@ -1,30 +0,0 @@
1
- import { getLocaleText } from '@hed-hog/api-locale';
2
- import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';
3
-
4
- export class CreateDTO {
5
- @IsNumber({}, { message: (args) => getLocaleText('validation.numberRequired', args.value) })
6
- address_type_id: number;
7
-
8
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
9
- country_code: string;
10
-
11
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
12
- state: string;
13
-
14
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
15
- city: string;
16
-
17
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
18
- postal_code: string;
19
-
20
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
21
- line1: string;
22
-
23
- @IsOptional()
24
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
25
- line2?: string;
26
-
27
- @IsOptional()
28
- @IsBoolean({ message: (args) => getLocaleText('validation.booleanRequired', args.value) })
29
- is_primary?: boolean;
30
- }
@@ -1,4 +0,0 @@
1
- import { PartialType } from '@nestjs/mapped-types';
2
- import { CreateDTO } from './create.dto';
3
-
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
@@ -1,67 +0,0 @@
1
- import { DeleteDTO, Role } from '@hed-hog/api';
2
- import { Pagination } from '@hed-hog/api-pagination';
3
- import {
4
- Body,
5
- Controller,
6
- Delete,
7
- Get,
8
- Inject,
9
- Param,
10
- ParseIntPipe,
11
- Patch,
12
- Post,
13
- forwardRef
14
- } from '@nestjs/common';
15
- import { PersonContactService } from './contact.service';
16
- import { CreateDTO } from './dto/create.dto';
17
- import { UpdateDTO } from './dto/update.dto';
18
-
19
- @Role()
20
- @Controller('person/:personId/person-contact')
21
- export class PersonContactController {
22
- constructor(
23
- @Inject(forwardRef(() => PersonContactService))
24
- private readonly personContactService: PersonContactService
25
- ) {}
26
-
27
- @Post()
28
- create(
29
- @Param('personId', ParseIntPipe) personId: number,
30
- @Body() data: CreateDTO
31
- ) {
32
- return this.personContactService.create(personId, data);
33
- }
34
-
35
- @Get()
36
- list(
37
- @Param('personId', ParseIntPipe) personId: number,
38
- @Pagination() paginationParams
39
- ) {
40
- return this.personContactService.list(paginationParams, personId);
41
- }
42
-
43
- @Get(':id')
44
- get(
45
- @Param('personId', ParseIntPipe) personId: number,
46
- @Param('id', ParseIntPipe) id: number
47
- ) {
48
- return this.personContactService.get(personId, id);
49
- }
50
-
51
- @Patch(':id')
52
- update(
53
- @Param('personId', ParseIntPipe) personId: number,
54
- @Param('id', ParseIntPipe) id: number,
55
- @Body() data: UpdateDTO
56
- ) {
57
- return this.personContactService.update(personId, id, data);
58
- }
59
-
60
- @Delete()
61
- delete(
62
- @Param('personId', ParseIntPipe) personId: number,
63
- @Body() { ids }: DeleteDTO
64
- ) {
65
- return this.personContactService.delete(personId, { ids });
66
- }
67
- }
@@ -1,83 +0,0 @@
1
- import { DeleteDTO } from '@hed-hog/api';
2
- import { getLocaleText } from '@hed-hog/api-locale';
3
- import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
4
- import { PrismaService } from '@hed-hog/api-prisma';
5
- import {
6
- BadRequestException,
7
- Injectable
8
- } from '@nestjs/common';
9
- import { CreateDTO } from './dto/create.dto';
10
- import { UpdateDTO } from './dto/update.dto';
11
-
12
- @Injectable()
13
- export class PersonContactService {
14
- constructor(
15
- private readonly prismaService: PrismaService,
16
- private readonly paginationService: PaginationService
17
- ) {}
18
-
19
- async create(personId: number, data: CreateDTO) {
20
- return this.prismaService.contact.create({
21
- data: {
22
- person_id: personId,
23
- ...data
24
- }
25
- });
26
- }
27
-
28
- async get(personId: number, id: number) {
29
- return this.prismaService.contact.findFirst({
30
- where: {
31
- person_id: personId,
32
- id: id
33
- }
34
- });
35
- }
36
-
37
- async list(paginationParams: PaginationDTO, personId?: number) {
38
- const where: any = {};
39
- if (personId !== undefined) where.person_id = personId;
40
-
41
- return this.paginationService.paginate(
42
- this.prismaService.contact,
43
- {
44
- fields: 'is_primary,value',
45
- ...paginationParams
46
- },
47
- {
48
- where
49
- }
50
- );
51
- }
52
-
53
- async update(personId: number, id: number, data: UpdateDTO) {
54
- return this.prismaService.contact.updateMany({
55
- where: {
56
- person_id: personId,
57
- id: id
58
- },
59
- data
60
- });
61
- }
62
-
63
- async delete(personId: number, { ids }: DeleteDTO, locale: string = 'en') {
64
- if (ids == undefined || ids == null) {
65
- throw new BadRequestException(
66
- getLocaleText(
67
- 'deleteItemsRequired',
68
- locale,
69
- 'You must select at least one item to delete.',
70
- ),
71
- );
72
- }
73
-
74
- return this.prismaService.contact.deleteMany({
75
- where: {
76
- person_id: personId,
77
- id: {
78
- in: ids
79
- }
80
- }
81
- });
82
- }
83
- }
@@ -1,14 +0,0 @@
1
- import { getLocaleText } from '@hed-hog/api-locale';
2
- import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';
3
-
4
- export class CreateDTO {
5
- @IsNumber({}, { message: (args) => getLocaleText('validation.numberRequired', args.value) })
6
- contact_type_id: number;
7
-
8
- @IsOptional()
9
- @IsBoolean({ message: (args) => getLocaleText('validation.booleanRequired', args.value) })
10
- is_primary?: boolean;
11
-
12
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
13
- value: string;
14
- }
@@ -1,4 +0,0 @@
1
- import { PartialType } from '@nestjs/mapped-types';
2
- import { CreateDTO } from './create.dto';
3
-
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
@@ -1,67 +0,0 @@
1
- import { DeleteDTO, Role } from '@hed-hog/api';
2
- import { Pagination } from '@hed-hog/api-pagination';
3
- import {
4
- Body,
5
- Controller,
6
- Delete,
7
- Get,
8
- Inject,
9
- Param,
10
- ParseIntPipe,
11
- Patch,
12
- Post,
13
- forwardRef
14
- } from '@nestjs/common';
15
- import { PersonDocumentService } from './document.service';
16
- import { CreateDTO } from './dto/create.dto';
17
- import { UpdateDTO } from './dto/update.dto';
18
-
19
- @Role()
20
- @Controller('person/:personId/person-document')
21
- export class PersonDocumentController {
22
- constructor(
23
- @Inject(forwardRef(() => PersonDocumentService))
24
- private readonly personDocumentService: PersonDocumentService
25
- ) {}
26
-
27
- @Post()
28
- create(
29
- @Param('personId', ParseIntPipe) personId: number,
30
- @Body() data: CreateDTO
31
- ) {
32
- return this.personDocumentService.create(personId, data);
33
- }
34
-
35
- @Get()
36
- list(
37
- @Param('personId', ParseIntPipe) personId: number,
38
- @Pagination() paginationParams
39
- ) {
40
- return this.personDocumentService.list(paginationParams, personId);
41
- }
42
-
43
- @Get(':id')
44
- get(
45
- @Param('personId', ParseIntPipe) personId: number,
46
- @Param('id', ParseIntPipe) id: number
47
- ) {
48
- return this.personDocumentService.get(personId, id);
49
- }
50
-
51
- @Patch(':id')
52
- update(
53
- @Param('personId', ParseIntPipe) personId: number,
54
- @Param('id', ParseIntPipe) id: number,
55
- @Body() data: UpdateDTO
56
- ) {
57
- return this.personDocumentService.update(personId, id, data);
58
- }
59
-
60
- @Delete()
61
- delete(
62
- @Param('personId', ParseIntPipe) personId: number,
63
- @Body() { ids }: DeleteDTO
64
- ) {
65
- return this.personDocumentService.delete(personId, { ids });
66
- }
67
- }
@@ -1,83 +0,0 @@
1
- import { DeleteDTO } from '@hed-hog/api';
2
- import { getLocaleText } from '@hed-hog/api-locale';
3
- import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
4
- import { PrismaService } from '@hed-hog/api-prisma';
5
- import {
6
- BadRequestException,
7
- Injectable
8
- } from '@nestjs/common';
9
- import { CreateDTO } from './dto/create.dto';
10
- import { UpdateDTO } from './dto/update.dto';
11
-
12
- @Injectable()
13
- export class PersonDocumentService {
14
- constructor(
15
- private readonly prismaService: PrismaService,
16
- private readonly paginationService: PaginationService
17
- ) {}
18
-
19
- async create(personId: number, data: CreateDTO) {
20
- return this.prismaService.document.create({
21
- data: {
22
- person_id: personId,
23
- ...data
24
- }
25
- });
26
- }
27
-
28
- async get(personId: number, id: number) {
29
- return this.prismaService.document.findFirst({
30
- where: {
31
- person_id: personId,
32
- id: id
33
- }
34
- });
35
- }
36
-
37
- async list(paginationParams: PaginationDTO, personId?: number) {
38
- const where: any = {};
39
- if (personId !== undefined) where.person_id = personId;
40
-
41
- return this.paginationService.paginate(
42
- this.prismaService.document,
43
- {
44
- fields: 'value',
45
- ...paginationParams
46
- },
47
- {
48
- where
49
- }
50
- );
51
- }
52
-
53
- async update(personId: number, id: number, data: UpdateDTO) {
54
- return this.prismaService.document.updateMany({
55
- where: {
56
- person_id: personId,
57
- id: id
58
- },
59
- data
60
- });
61
- }
62
-
63
- async delete(personId: number, { ids }: DeleteDTO, locale: string = 'en') {
64
- if (ids == undefined || ids == null) {
65
- throw new BadRequestException(
66
- getLocaleText(
67
- 'deleteItemsRequired',
68
- locale,
69
- 'You must select at least one item to delete.',
70
- ),
71
- );
72
- }
73
-
74
- return this.prismaService.document.deleteMany({
75
- where: {
76
- person_id: personId,
77
- id: {
78
- in: ids
79
- }
80
- }
81
- });
82
- }
83
- }
@@ -1,10 +0,0 @@
1
- import { getLocaleText } from '@hed-hog/api-locale';
2
- import { IsNumber, IsString } from 'class-validator';
3
-
4
- export class CreateDTO {
5
- @IsNumber({}, { message: (args) => getLocaleText('validation.numberRequired', args.value) })
6
- document_type_id: number;
7
-
8
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
9
- value: string;
10
- }
@@ -1,4 +0,0 @@
1
- import { PartialType } from '@nestjs/mapped-types';
2
- import { CreateDTO } from './create.dto';
3
-
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
@@ -1,14 +0,0 @@
1
- import { getLocaleText } from '@hed-hog/api-locale';
2
- import { Type } from 'class-transformer';
3
- import { IsDate, IsNotEmpty, IsString } from 'class-validator';
4
-
5
- export class CreateDTO {
6
- @IsNotEmpty({ message: (args) => getLocaleText('validation.fieldRequired', args.value) })
7
- @IsDate({ message: (args) => getLocaleText('validation.dateInvalid', args.value) })
8
- @Type(() => Date)
9
- foundation_date: Date;
10
-
11
- @IsNotEmpty({ message: (args) => getLocaleText('validation.fieldRequired', args.value) })
12
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
13
- legal_nature: string;
14
- }
@@ -1,4 +0,0 @@
1
- import { PartialType } from '@nestjs/mapped-types';
2
- import { CreateDTO } from './create.dto';
3
-
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
@@ -1,45 +0,0 @@
1
- import { Role } from '@hed-hog/api';
2
- import {
3
- Body,
4
- Controller,
5
- Get,
6
- Inject,
7
- Param,
8
- ParseIntPipe,
9
- Patch,
10
- Post,
11
- forwardRef
12
- } from '@nestjs/common';
13
- import { CreateDTO } from './dto/create.dto';
14
- import { UpdateDTO } from './dto/update.dto';
15
- import { PersonCompanyService } from './person-company.service';
16
-
17
- @Role()
18
- @Controller('person/:personId/person-company')
19
- export class PersonCompanyController {
20
- constructor(
21
- @Inject(forwardRef(() => PersonCompanyService))
22
- private readonly personCompanyService: PersonCompanyService
23
- ) {}
24
-
25
- @Post()
26
- create(
27
- @Param('personId', ParseIntPipe) personId: number,
28
- @Body() data: CreateDTO
29
- ) {
30
- return this.personCompanyService.create(data);
31
- }
32
-
33
- @Get()
34
- get(@Param('personId', ParseIntPipe) personId: number) {
35
- return this.personCompanyService.get(personId);
36
- }
37
-
38
- @Patch()
39
- update(
40
- @Param('personId', ParseIntPipe) personId: number,
41
- @Body() data: UpdateDTO
42
- ) {
43
- return this.personCompanyService.update(personId, data);
44
- }
45
- }