@@ -203,20 +203,28 @@ function toNumber(value: unknown): number | null {
203203 return typeof value === ' number' && Number .isFinite (value ) ? value : null
204204}
205205
206- function toValidationStatus(value : unknown ): ValidationStatus | null {
206+ const VALIDATION_STATUS_VALUES: readonly ValidationStatus [] = [
207+ FILE_STATUS .DRAFT ,
208+ FILE_STATUS .ABLE_TO_SIGN ,
209+ FILE_STATUS .PARTIAL_SIGNED ,
210+ FILE_STATUS .SIGNED ,
211+ FILE_STATUS .DELETED ,
212+ ]
213+
214+ function isValidationStatus(value : unknown ): value is ValidationStatus {
207215 const normalizedValue = toNumber (value )
208- if (normalizedValue === 0 || normalizedValue === 1 || normalizedValue === 2 || normalizedValue === 3 || normalizedValue === 4 ) {
209- return normalizedValue
210- }
211- return null
216+ return normalizedValue !== null && VALIDATION_STATUS_VALUES .includes (normalizedValue as ValidationStatus )
212217}
213218
214- function toSignerStatus(value : unknown ): SignerDetailRecord [' status' ] | null {
219+ const SIGNER_STATUS_VALUES: readonly SignerDetailRecord [' status' ][] = [
220+ SIGN_REQUEST_STATUS .DRAFT ,
221+ SIGN_REQUEST_STATUS .ABLE_TO_SIGN ,
222+ SIGN_REQUEST_STATUS .SIGNED ,
223+ ]
224+
225+ function isSignerStatus(value : unknown ): value is SignerDetailRecord [' status' ] {
215226 const normalizedValue = toNumber (value )
216- if (normalizedValue === 0 || normalizedValue === 1 || normalizedValue === 2 ) {
217- return normalizedValue
218- }
219- return null
227+ return normalizedValue !== null && SIGNER_STATUS_VALUES .includes (normalizedValue as SignerDetailRecord [' status' ])
220228}
221229
222230function isString(value : unknown ): value is string {
@@ -263,7 +271,7 @@ function isSignerDetailRecord(value: unknown): value is SignerDetailRecord {
263271 && isString (value .displayName )
264272 && isString (value .email )
265273 && isNullableString (value .signed )
266- && toSignerStatus (value .status ) !== null
274+ && isSignerStatus (value .status )
267275 && isString (value .statusText )
268276 && isNullableString (value .description )
269277 && isString (value .request_sign_date )
@@ -279,7 +287,7 @@ function isValidatedChildFileRecord(value: unknown): value is ValidatedChildFile
279287 return typeof value .id === ' number'
280288 && isString (value .uuid )
281289 && isString (value .name )
282- && toValidationStatus (value .status ) !== null
290+ && isValidationStatus (value .status )
283291 && isString (value .statusText )
284292 && typeof value .nodeId === ' number'
285293 && typeof value .size === ' number'
@@ -296,7 +304,7 @@ function isValidationDocumentRecord(data: unknown): data is ValidationFileRecord
296304 typeof data .id !== ' number'
297305 || ! isString (data .uuid )
298306 || ! isString (data .name )
299- || toValidationStatus (data .status ) === null
307+ || ! isValidationStatus (data .status )
300308 || ! isString (data .statusText )
301309 || typeof data .nodeId !== ' number'
302310 || (data .nodeType !== ' file' && data .nodeType !== ' envelope' )
0 commit comments