Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Unike
/
UnikeInspection-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
877f3f7a
authored
May 05, 2025
by
Augusto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
version 0.0.1
parent
8bbe41f2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
124 additions
and
14 deletions
+124
-14
src/modules/candidates/candidates.service.ts
+38
-2
src/modules/candidates/dto/create-candidate.dto.ts
+8
-3
src/modules/candidates/dto/update-candidate.dto.ts
+4
-3
src/modules/comments/comments.controller.ts
+21
-5
src/modules/comments/comments.service.ts
+26
-1
src/modules/comments/dto/create-comment.dto.ts
+14
-0
src/modules/comments/dto/update-comment.dto.ts
+13
-0
No files found.
src/modules/candidates/candidates.service.ts
View file @
877f3f7a
...
...
@@ -11,7 +11,7 @@ export class CandidatesService {
constructor
(
private
prisma
:
PrismaService
)
{
}
async
create
(
createCandidateDto
:
CreateCandidateDto
,
userId
?:
number
)
{
const
{
comment
,
...
candidateData
}
=
createCandidateDto
;
const
{
comment
,
siteIds
,
...
candidateData
}
=
createCandidateDto
;
// Create the candidate with a transaction to ensure both operations succeed or fail together
return
this
.
prisma
.
$transaction
(
async
(
prisma
)
=>
{
...
...
@@ -21,8 +21,20 @@ export class CandidatesService {
...
candidateData
,
createdById
:
userId
,
updatedById
:
userId
,
sites
:
{
create
:
siteIds
.
map
(
siteId
=>
({
site
:
{
connect
:
{
id
:
siteId
}
}
}))
}
},
include
:
{
sites
:
{
include
:
{
site
:
true
}
},
comments
:
{
include
:
{
createdBy
:
{
...
...
@@ -54,6 +66,11 @@ export class CandidatesService {
return
prisma
.
candidate
.
findUnique
({
where
:
{
id
:
candidate
.
id
},
include
:
{
sites
:
{
include
:
{
site
:
true
}
},
comments
:
{
include
:
{
createdBy
:
{
...
...
@@ -172,10 +189,29 @@ export class CandidatesService {
async
update
(
id
:
number
,
updateCandidateDto
:
UpdateCandidateDto
)
{
try
{
const
{
siteIds
,
...
candidateData
}
=
updateCandidateDto
;
return
await
this
.
prisma
.
candidate
.
update
({
where
:
{
id
},
data
:
updateCandidateDto
,
data
:
{
...
candidateData
,
...(
siteIds
&&
{
sites
:
{
deleteMany
:
{},
// Remove all existing site associations
create
:
siteIds
.
map
(
siteId
=>
({
site
:
{
connect
:
{
id
:
siteId
}
}
}))
}
})
},
include
:
{
sites
:
{
include
:
{
site
:
true
}
},
comments
:
{
include
:
{
createdBy
:
{
...
...
src/modules/candidates/dto/create-candidate.dto.ts
View file @
877f3f7a
...
...
@@ -12,6 +12,11 @@ export enum CandidateStatus {
PENDING
=
'PENDING'
,
APPROVED
=
'APPROVED'
,
REJECTED
=
'REJECTED'
,
NEGOTIATION_ONGOING
=
'NEGOTIATION_ONGOING'
,
MNO_VALIDATION
=
'MNO_VALIDATION'
,
CLOSING
=
'CLOSING'
,
SEARCH_AREA
=
'SEARCH_AREA'
,
}
export
class
CreateCandidateDto
{
...
...
@@ -43,9 +48,9 @@ export class CreateCandidateDto {
@
IsBoolean
()
onGoing
:
boolean
;
@
ApiProperty
({
description
:
'ID
of the site this candidate belongs to'
})
@
IsNumber
()
siteId
:
number
;
@
ApiProperty
({
description
:
'ID
s of the sites this candidate belongs to'
,
type
:
[
Number
]
})
@
IsNumber
(
{},
{
each
:
true
}
)
siteId
s
:
number
[]
;
@
ApiPropertyOptional
({
description
:
'Initial comment for the candidate'
})
@
IsString
()
...
...
src/modules/candidates/dto/update-candidate.dto.ts
View file @
877f3f7a
...
...
@@ -38,8 +38,8 @@ export class UpdateCandidateDto {
@
IsBoolean
()
onGoing
?:
boolean
;
@
ApiPropertyOptional
({
description
:
'ID
of the site this candidate belongs to'
})
@
ApiPropertyOptional
({
description
:
'ID
s of the sites this candidate belongs to'
,
type
:
[
Number
]
})
@
IsOptional
()
@
IsNumber
()
siteId
?:
number
;
@
IsNumber
(
{},
{
each
:
true
}
)
siteId
s
?:
number
[]
;
}
\ No newline at end of file
src/modules/comments/comments.controller.ts
View file @
877f3f7a
import
{
Controller
,
Get
,
Post
,
Body
,
Param
,
Delete
,
UseGuards
,
ParseIntPipe
}
from
'@nestjs/common'
;
import
{
ApiTags
,
ApiOperation
,
ApiResponse
,
ApiBearerAuth
}
from
'@nestjs/swagger'
;
import
{
Controller
,
Get
,
Post
,
Body
,
Param
,
Delete
,
UseGuards
,
ParseIntPipe
,
Req
,
Put
}
from
'@nestjs/common'
;
import
{
ApiTags
,
ApiOperation
,
ApiResponse
,
ApiBearerAuth
,
ApiBody
}
from
'@nestjs/swagger'
;
import
{
CommentsService
}
from
'./comments.service'
;
import
{
CreateCommentDto
}
from
'./dto/create-comment.dto'
;
import
{
UpdateCommentDto
}
from
'./dto/update-comment.dto'
;
import
{
CommentResponseDto
}
from
'./dto/comment-response.dto'
;
import
{
JwtAuthGuard
}
from
'../auth/guards/jwt-auth.guard'
;
import
{
RolesGuard
}
from
'../auth/guards/roles.guard'
;
import
{
Roles
}
from
'../auth/decorators/roles.decorator'
;
import
{
Role
}
from
'@prisma/client'
;
import
{
Request
}
from
'express'
;
@
ApiTags
(
'comments'
)
@
Controller
(
'comments'
)
...
...
@@ -16,11 +18,14 @@ export class CommentsController {
constructor
(
private
readonly
commentsService
:
CommentsService
)
{
}
@
Post
()
@
Roles
(
Role
.
ADMIN
,
Role
.
MANAGER
,
Role
.
OPERATOR
)
@
Roles
(
Role
.
ADMIN
,
Role
.
MANAGER
,
Role
.
OPERATOR
,
Role
.
SUPERADMIN
)
@
ApiOperation
({
summary
:
'Create a new comment'
})
@
ApiBody
({
type
:
CreateCommentDto
})
@
ApiResponse
({
status
:
201
,
description
:
'The comment has been successfully created.'
,
type
:
CommentResponseDto
})
@
ApiResponse
({
status
:
400
,
description
:
'Bad Request.'
})
create
(@
Body
()
createCommentDto
:
CreateCommentDto
)
{
create
(@
Body
()
createCommentDto
:
CreateCommentDto
,
@
Req
()
req
:
Request
)
{
const
user
=
req
.
user
as
any
;
createCommentDto
.
createdById
=
user
.
id
;
return
this
.
commentsService
.
create
(
createCommentDto
);
}
...
...
@@ -44,11 +49,21 @@ export class CommentsController {
}
@
Delete
(
':id'
)
@
Roles
(
Role
.
ADMIN
,
Role
.
MANAGER
)
@
Roles
(
Role
.
ADMIN
,
Role
.
MANAGER
,
Role
.
SUPERADMIN
)
@
ApiOperation
({
summary
:
'Delete a comment'
})
@
ApiResponse
({
status
:
200
,
description
:
'The comment has been successfully deleted.'
,
type
:
CommentResponseDto
})
@
ApiResponse
({
status
:
404
,
description
:
'Comment not found.'
})
remove
(@
Param
(
'id'
,
ParseIntPipe
)
id
:
number
)
{
return
this
.
commentsService
.
remove
(
id
);
}
@
Put
(
':id'
)
@
Roles
(
Role
.
ADMIN
,
Role
.
MANAGER
,
Role
.
OPERATOR
,
Role
.
SUPERADMIN
)
@
ApiOperation
({
summary
:
'Update a comment'
})
@
ApiBody
({
type
:
UpdateCommentDto
})
@
ApiResponse
({
status
:
200
,
description
:
'The comment has been successfully updated.'
,
type
:
CommentResponseDto
})
@
ApiResponse
({
status
:
404
,
description
:
'Comment not found.'
})
update
(@
Param
(
'id'
,
ParseIntPipe
)
id
:
number
,
@
Body
()
updateCommentDto
:
UpdateCommentDto
)
{
return
this
.
commentsService
.
update
(
id
,
updateCommentDto
);
}
}
\ No newline at end of file
src/modules/comments/comments.service.ts
View file @
877f3f7a
import
{
Injectable
}
from
'@nestjs/common'
;
import
{
Injectable
,
NotFoundException
}
from
'@nestjs/common'
;
import
{
PrismaService
}
from
'../../common/prisma/prisma.service'
;
import
{
CreateCommentDto
}
from
'./dto/create-comment.dto'
;
import
{
UpdateCommentDto
}
from
'./dto/update-comment.dto'
;
@
Injectable
()
export
class
CommentsService
{
...
...
@@ -65,4 +66,27 @@ export class CommentsService {
where
:
{
id
},
});
}
async
update
(
id
:
number
,
updateCommentDto
:
UpdateCommentDto
)
{
try
{
return
await
this
.
prisma
.
comment
.
update
({
where
:
{
id
},
data
:
{
content
:
updateCommentDto
.
content
,
updatedAt
:
new
Date
(),
},
include
:
{
createdBy
:
{
select
:
{
id
:
true
,
name
:
true
,
email
:
true
,
},
},
},
});
}
catch
(
error
)
{
throw
new
NotFoundException
(
`Comment with ID
${
id
}
not found`
);
}
}
}
\ No newline at end of file
src/modules/comments/dto/create-comment.dto.ts
View file @
877f3f7a
import
{
IsString
,
IsNotEmpty
,
IsInt
,
IsOptional
}
from
'class-validator'
;
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
export
class
CreateCommentDto
{
@
ApiProperty
({
description
:
'The content of the comment'
,
example
:
'This is a comment about the candidate'
})
@
IsString
()
@
IsNotEmpty
()
content
:
string
;
@
ApiProperty
({
description
:
'The ID of the candidate this comment is for'
,
example
:
64
})
@
IsInt
()
@
IsNotEmpty
()
candidateId
:
number
;
@
ApiProperty
({
description
:
'The ID of the user creating the comment (optional, will be set automatically)'
,
example
:
1
,
required
:
false
})
@
IsInt
()
@
IsOptional
()
createdById
?:
number
;
...
...
src/modules/comments/dto/update-comment.dto.ts
0 → 100644
View file @
877f3f7a
import
{
IsString
,
IsNotEmpty
,
IsOptional
}
from
'class-validator'
;
import
{
ApiProperty
}
from
'@nestjs/swagger'
;
export
class
UpdateCommentDto
{
@
ApiProperty
({
description
:
'The updated content of the comment'
,
example
:
'This is an updated comment about the candidate'
})
@
IsString
()
@
IsNotEmpty
()
content
:
string
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment