Skip to content

Instantly share code, notes, and snippets.

@jtomchak
Created April 13, 2022 17:30
Show Gist options
  • Save jtomchak/ebc84c4114e1603c989dab40279243b3 to your computer and use it in GitHub Desktop.
Save jtomchak/ebc84c4114e1603c989dab40279243b3 to your computer and use it in GitHub Desktop.
import { Handler } from 'express';
import store from 'node-persist';
import { User } from '../../types';
import { DocuSignError } from '../docusign-error';
import { DocuSignUser, listEnvelopes } from '../lib';
export const getAllEnvelopes: Handler = async (req, res) => {
const { access_token } = res.locals.user as User & DocuSignUser;
const { customerEmail, searchText } = req.query as Record<string, string>;
const account_id = await store.getItem('docuSignAccountId');
const args = { access_token, account_id, customerEmail, searchText };
if (!account_id) {
return res.sendStatus(401);
}
try {
const results = await listEnvelopes(args);
res.status(200).send({
message: 'Results from the Envelopes::listStatusChanges method',
data: results,
});
} catch (err) {
const error = err as DocuSignError;
const errorBody = error && error.response && error.response.body;
const errorCode = errorBody && errorBody.errorCode;
const errorMessage = errorBody && errorBody.message;
res.status(error.status || 400).send({
error: err,
errorCode,
message: errorMessage,
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment