Skip to content

Instantly share code, notes, and snippets.

@the-frey
Last active March 9, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-frey/ad36baa1e86c4669e9ab45f43326e5a0 to your computer and use it in GitHub Desktop.
Save the-frey/ad36baa1e86c4669e9ab45f43326e5a0 to your computer and use it in GitHub Desktop.
// 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