From 0fcdf234fe3f2cb5be7491c100596c70e426cc52 Mon Sep 17 00:00:00 2001 From: Emanuele De Cupis Date: Thu, 23 Jul 2020 14:10:11 +0200 Subject: [PATCH] removed curly braces --- DeleteUserDataActivity/backupAndDelete.ts | 191 ++++++++++------------ 1 file changed, 90 insertions(+), 101 deletions(-) diff --git a/DeleteUserDataActivity/backupAndDelete.ts b/DeleteUserDataActivity/backupAndDelete.ts index fae9f41c..4e888e43 100644 --- a/DeleteUserDataActivity/backupAndDelete.ts +++ b/DeleteUserDataActivity/backupAndDelete.ts @@ -56,56 +56,53 @@ const executeRecursiveBackupAndDelete = ( // tslint:disable-next-line: use-type-alias DataFailure, readonly T[] -> => { - return ( - tryCatch(iterator.executeNext, toError) - // this is just type lifting - .foldTaskEither>( - e => fromLeft(toQueryFailure(e)), - e => fromEither(e).mapLeft(toQueryFailure) - ) - .chain(maybeResults => - maybeResults.fold( - // if the iterator content is none, exit the recursion - taskEither.of([]), - items => - // executes backup&delete for this set of items - array.sequence(taskEither)( - items.map((item: T) => - sequenceT(taskEitherSeq)< - DataFailure, +> => + tryCatch(iterator.executeNext, toError) + // this is just type lifting + .foldTaskEither>( + e => fromLeft(toQueryFailure(e)), + e => fromEither(e).mapLeft(toQueryFailure) + ) + .chain(maybeResults => + maybeResults.fold( + // if the iterator content is none, exit the recursion + taskEither.of([]), + items => + // executes backup&delete for this set of items + array.sequence(taskEither)( + items.map((item: T) => + sequenceT(taskEitherSeq)< + DataFailure, + // tslint:disable-next-line: readonly-array + [ + TaskEither, + TaskEither, // tslint:disable-next-line: readonly-array - [ - TaskEither, - TaskEither, - // tslint:disable-next-line: readonly-array - TaskEither - ] - >( - saveDataToBlob( - userDataBackup, - makeBackupBlobName(item), - item - ), - tryCatch(() => deleteSingle(item), toError) - .mapLeft(toDocumentDeleteFailure) - .chain(_ => fromEither(_).mapLeft(toDocumentDeleteFailure)), - // recursive step - executeRecursiveBackupAndDelete( - deleteSingle, - userDataBackup, - makeBackupBlobName, - iterator - ) + TaskEither + ] + >( + saveDataToBlob( + userDataBackup, + makeBackupBlobName(item), + item + ), + tryCatch(() => deleteSingle(item), toError) + .mapLeft(toDocumentDeleteFailure) + .chain(_ => fromEither(_).mapLeft(toDocumentDeleteFailure)), + // recursive step + executeRecursiveBackupAndDelete( + deleteSingle, + userDataBackup, + makeBackupBlobName, + iterator ) - // aggregates the results at the end of the recursion - .map(([_, __, nextResults]) => [item, ...nextResults]) ) + // aggregates the results at the end of the recursion + .map(([_, __, nextResults]) => [item, ...nextResults]) ) - ) + ) ) - ); -}; + ); /** * Backup and delete every version of the profile @@ -122,14 +119,13 @@ const backupAndDeleteProfile = ({ profileModel: ProfileDeletableModel; userDataBackup: IBlobServiceInfo; fiscalCode: FiscalCode; -}) => { - return executeRecursiveBackupAndDelete( +}) => + executeRecursiveBackupAndDelete( item => profileModel.deleteProfileVersion(item.fiscalCode, item.id), userDataBackup, item => `profile/${item.id}.json`, profileModel.findAllVersionsByModelId(fiscalCode) ); -}; /** * Backup and delete a given notification @@ -146,8 +142,8 @@ const backupAndDeleteNotification = ({ notificationModel: NotificationDeletableModel; userDataBackup: IBlobServiceInfo; notification: RetrievedNotification; -}): TaskEither => { - return sequenceT(taskEitherSeq)< +}): TaskEither => + sequenceT(taskEitherSeq)< DataFailure, // tslint:disable-next-line: readonly-array [ @@ -167,7 +163,6 @@ const backupAndDeleteNotification = ({ ) ).mapLeft(toDocumentDeleteFailure) ).map(_ => notification); -}; /** * Find all versions of a notification status, then backup and delete each document @@ -212,8 +207,8 @@ const backupAndDeleteMessage = ({ messageModel: MessageDeletableModel; userDataBackup: IBlobServiceInfo; message: RetrievedMessageWithoutContent; -}): TaskEither => { - return sequenceT(taskEitherSeq)< +}): TaskEither => + sequenceT(taskEitherSeq)< DataFailure, // tslint:disable-next-line: readonly-array [ @@ -230,7 +225,6 @@ const backupAndDeleteMessage = ({ messageModel.deleteMessage(message.fiscalCode, message.id) ).mapLeft(toDocumentDeleteFailure) ).map(_ => message); -}; const backupAndDeleteMessageContent = ({ messageContentBlobService, @@ -242,48 +236,45 @@ const backupAndDeleteMessageContent = ({ messageModel: MessageDeletableModel; userDataBackup: IBlobServiceInfo; message: RetrievedMessageWithoutContent; -}): TaskEither> => { - return ( - tryCatch( - () => - messageModel.getContentFromBlob(messageContentBlobService, message.id), - toError - ) - // type lift - // from TaskEither of Either of Option of X - // to TaskEither of X - // this way we collaps every left/none case into the same path - .chain(fromEither) - .chain(e => fromEither(fromOption(undefined)(e))) - .foldTaskEither>( - _ => { - // unfortunately, a document not found is threated like a query error - return taskEither.of(none); - }, - content => - taskEither - .of(void 0) - .chain(_ => - saveDataToBlob( - userDataBackup, - `message-content/${message.id}.json`, - content - ) - ) - .chain(_ => - tryCatch( - () => - messageModel.deleteContentFromBlob( - messageContentBlobService, - message.id - ), - toError - ).mapLeft(toDocumentDeleteFailure) +}): TaskEither> => + tryCatch( + () => + messageModel.getContentFromBlob(messageContentBlobService, message.id), + toError + ) + // type lift + // from TaskEither of Either of Option of X + // to TaskEither of X + // this way we collaps every left/none case into the same path + .chain(fromEither) + .chain(e => fromEither(fromOption(undefined)(e))) + .foldTaskEither>( + _ => { + // unfortunately, a document not found is threated like a query error + return taskEither.of(none); + }, + content => + taskEither + .of(void 0) + .chain(_ => + saveDataToBlob( + userDataBackup, + `message-content/${message.id}.json`, + content ) - .map(_ => some(content)) - ) - ); -}; + ) + .chain(_ => + tryCatch( + () => + messageModel.deleteContentFromBlob( + messageContentBlobService, + message.id + ), + toError + ).mapLeft(toDocumentDeleteFailure) + ) + .map(_ => some(content)) + ); /** * Find all versions of a message status, then backup and delete each document @@ -300,15 +291,14 @@ const backupAndDeleteMessageStatus = ({ messageStatusModel: MessageStatusDeletableModel; userDataBackup: IBlobServiceInfo; message: RetrievedMessageWithoutContent; -}): TaskEither => { - return executeRecursiveBackupAndDelete( +}): TaskEither => + executeRecursiveBackupAndDelete( item => messageStatusModel.deleteMessageStatusVersion(item.messageId, item.id), userDataBackup, item => `message-status/${item.id}.json`, messageStatusModel.findAllVersionsByModelId(message.id) ); -}; /** * For a given message, search all its notifications and backup&delete each one including its own notification status @@ -457,8 +447,8 @@ export const backupAndDeleteAllUserData = ({ profileModel: ProfileDeletableModel; userDataBackup: IBlobServiceInfo; fiscalCode: FiscalCode; -}) => { - return backupAndDeleteAllMessagesData({ +}) => + backupAndDeleteAllMessagesData({ fiscalCode, messageContentBlobService, messageModel, @@ -469,4 +459,3 @@ export const backupAndDeleteAllUserData = ({ }).chain(_ => backupAndDeleteProfile({ profileModel, userDataBackup, fiscalCode }) ); -};