File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed
Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ module.exports = {
99 try {
1010 const ticket = new TicketModel ( req . body )
1111 ticket . createdBy = userId
12+ ticket . history . push ( { ...req . body , editedBy : userId } )
1213 await ticket . save ( )
1314 res . status ( HttpStatus . CREATED ) . json ( {
1415 ticket : ticket
@@ -51,13 +52,16 @@ module.exports = {
5152 // Only user who created the ticket and admin can edit the ticket
5253 return res . status ( HttpStatus . FORBIDDEN ) . json ( { error : 'Edit Forbidden by user' } )
5354 }
54- ticket . title = title
55- if ( content . shortDescription ) {
56- ticket . content . shortDescription = content . shortDescription
57- }
58- if ( content . longDescription ) {
59- ticket . content . longDescription = content . longDescription
55+ if ( ticket . title === title &&
56+ ticket . content . shortDescription === content . shortDescription &&
57+ ticket . content . longDescription === content . longDescription ) {
58+ return res . status ( HttpStatus . NOT_MODIFIED ) . json ( { error : 'No changes to ticket' } )
6059 }
60+ ticket . title = title
61+ ticket . content . shortDescription = content . shortDescription
62+ ticket . content . longDescription = content . longDescription
63+ ticket . history . push ( { title, content, editedBy : userId , editedAt : Date . now ( ) } )
64+ ticket . updatedAt = Date . now ( )
6165 await ticket . save ( )
6266 res . status ( HttpStatus . OK ) . json ( {
6367 ticket : ticket
Original file line number Diff line number Diff line change @@ -52,6 +52,33 @@ const ticketSchema = new Schema({
5252 }
5353 }
5454 ] ,
55+ history : [
56+ {
57+ title : {
58+ type : String ,
59+ trim : true
60+ } ,
61+ content : {
62+ shortDescription : {
63+ type : String ,
64+ trim : true
65+ } ,
66+ longDescription : {
67+ type : String ,
68+ trim : true
69+ }
70+ } ,
71+ editedAt : {
72+ type : Date ,
73+ required : true ,
74+ default : Date . now ( )
75+ } ,
76+ editedBy : {
77+ type : Schema . Types . ObjectId ,
78+ ref : 'User'
79+ }
80+ }
81+ ] ,
5582 comments : [
5683 {
5784 content : {
You can’t perform that action at this time.
0 commit comments