-
-
Save the-frey/ad36baa1e86c4669e9ab45f43326e5a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the handler NS we have our microservice | |
// which is an AWS Lambda | |
export const usersPublicGet = async (event: requests.MinimalRequestEvent): Promise<responses.Response> => { | |
const system: db.System = await db.getSystem(); | |
const client = system.pgclient; | |
try { | |
const response = await p.pipeline(event, up.getPublicPipeline)(system)(); | |
return response; | |
} catch (err) { | |
console.log(err); | |
return responses.respond500('http/error', 'Something went wrong'); | |
} finally { | |
await db.closeDbConn(client); | |
} | |
}; | |
// in the up (users pipeline) namespace we have lots of Do chains | |
// of RTE - ReaderTaskEither - monads | |
const getPublicPipeline = (event: requests.MinimalRequestEvent): RTE.ReaderTaskEither<db.System, t.ErrorType, t.EntityType> => | |
Do(RTE.readerTaskEither) | |
.bind('userId', RTE.fromEither(requests.getIdFromPath(event))) | |
.bindL('getUserRes', ({ userId }) => uDb.getUserRTE(userId)) | |
.bindL('user', ({ getUserRes }) => RTE.fromEither(uXfms.getUserFromResE(getUserRes))) | |
.bindL('userNoPII', ({ user }) => RTE.fromEither(uXfms.userToShareableE(user))) | |
.bindL('getUserFileRes', ({ user }) => fDb.getFileRTE(user.file_uuid)) | |
.bindL('userFile', ({ getUserFileRes }) => RTE.right(fXfms.getUserFileDataFromRes(getUserFileRes))) | |
.bindL('userNoPIIWithFile', ({ userNoPII, userFile }) => RTE.right(R.mergeRight(userNoPII, { file: userFile }))) | |
.return(({ userNoPIIWithFile }) => { return { entityType: t.EntityTypes.user, entity: userNoPIIWithFile }; }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment