Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature donation csv export #967

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/server/adminJs/adminJs-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ export interface AdminJsProjectsQuery {
reviewStatus: ReviewStatus;
}

export interface AdminJsDonationsQuery {
projectId?: string;
contactEmail?: string;
referrerWallet?: string;
userId?: string;
fromWalletAddress?: string;
toWalletAddress?: string;
status?: string;
createdAt?: string;
currency?: string;
transactionNetworkId?: string;
isProjectVerified?: string;
}

// headers defined by the verification team for exporting
export const headers = [
export const projectHeaders = [
'id',
'title',
'slug',
Expand All @@ -54,3 +68,29 @@ export const headers = [
'secondWalletAddress',
'secondWalletAddressNetwork',
];

export const donationHeaders = [
'id',
'transactionId',
'transactionNetworkId',
'isProjectVerified',
'status',
'toWalletAddress',
'fromWalletAddress',
'tokenAddress',
'currency',
'anonymous',
'amount',
'isFiat',
'isCustomToken',
'valueEth',
'valueUsd',
'priceEth',
'priceUsd',
'projectId',
'userId',
'contactEmail',
'createdAt',
'referrerWallet',
'isTokenEligibleForGivback',
];
19 changes: 12 additions & 7 deletions src/server/adminJs/adminJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,29 @@ export const getAdminJsRouter = async () => {
// Express Middleware to save query of a search
export const adminJsQueryCache = async (req, res, next) => {
if (
req.url.startsWith('/admin/api/resources/Project/actions/list') &&
req.headers.cookie.includes('adminjs')
req.url.startsWith('/admin/api/resources/') &&
req.headers.cookie.includes('adminbro')
) {
const admin = await getCurrentAdminJsSession(req);
if (!admin) return next(); // skip saving queries

const matches = req.url.match(/\/admin\/api\/resources\/(.+?)(\/|$)/);
if (!matches) return next(); // invalid URL

const resourceName = matches[1];
const queryStrings = {};
// get URL query strings

// Extract filter names and values from URL query string parameters
for (const key of Object.keys(req.query)) {
const [_, filter] = key.split('.');
if (!filter) continue;

queryStrings[filter] = req.query[key];
}
// save query string for later use with an expiration
await redis.set(
`adminjs_${admin.id}_qs`,
JSON.stringify(queryStrings),
// Save query strings to Redis hash with an expiration
await redis.hset(
`adminbro:${admin.id}:${resourceName}`,
queryStrings,
'ex',
1800,
);
Expand Down
3 changes: 3 additions & 0 deletions src/server/adminJs/adminJsPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,15 @@ const donationPermissions = {
new: true,
show: true,
edit: true,
exportFilterToCsv: true,
},
[UserRole.OPERATOR]: {
show: true,
exportFilterToCsv: true,
},
[UserRole.VERIFICATION_FORM_REVIEWER]: {
show: true,
exportFilterToCsv: true,
},
[UserRole.CAMPAIGN_MANAGER]: {
show: true,
Expand Down
Loading