@@ -5,6 +5,7 @@ import { IServiceOptions } from './IServiceOptions'
55import EagleEyeContentRepository from '../database/repositories/eagleEyeContentRepository'
66import { getConfig } from '../config'
77import Error400 from '../errors/Error403'
8+ import track from '../segment/track'
89
910interface EagleEyeSearchPoint {
1011 vectorId : string
@@ -118,11 +119,43 @@ export default class EagleEyeContentService {
118119 const transaction = await SequelizeRepository . createTransaction ( this . options . database )
119120
120121 try {
122+ const recordBeforeUpdate = await EagleEyeContentRepository . findById ( id , { ...this . options } )
121123 const record = await EagleEyeContentRepository . update ( id , data , {
122124 ...this . options ,
123125 transaction,
124126 } )
125127
128+ // If we are updating status we want to track it
129+ if ( data . status !== recordBeforeUpdate . status ) {
130+ // If we are going from null to status, we are either accepting or rejecting
131+ if ( data . status && data . status !== null && data . status !== undefined ) {
132+ track (
133+ `EagleEye ${ data . status } ` ,
134+ {
135+ ...data ,
136+ platform : record . platform ,
137+ keywords : record . keywords ,
138+ title : record . title ,
139+ url : record . url ,
140+ } ,
141+ { ...this . options } ,
142+ )
143+ // Here we are bringing back a rejected post to the Inbox
144+ } else if ( recordBeforeUpdate . status === 'rejected' && data . status === null ) {
145+ track (
146+ `EagleEye post from rejected to Inbox` ,
147+ {
148+ ...data ,
149+ platform : record . platform ,
150+ keywords : record . keywords ,
151+ title : record . title ,
152+ url : record . url ,
153+ } ,
154+ { ...this . options } ,
155+ )
156+ }
157+ }
158+
126159 await SequelizeRepository . commitTransaction ( transaction )
127160
128161 return record
0 commit comments