Skip to content

Commit

Permalink
feat(nomad-badges): Digital Nomad program
Browse files Browse the repository at this point in the history
- putBadges for level1,2,3,4
- sendmail for level1,2,3,4
- incremental levels 1 by 1, no skipping each level

for thematters/matters-server#3721
  • Loading branch information
Ubuntu authored and Ubuntu committed Dec 8, 2023
1 parent d26b7d2 commit de3620e
Show file tree
Hide file tree
Showing 4 changed files with 632 additions and 1 deletion.
11 changes: 11 additions & 0 deletions bin/check-nomad-badge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env -S node --trace-warnings --loader ts-node/esm

import { checkNomadBadge } from "../lib/check-nomad-badge.js";

async function main() {
const args = process.argv.slice(2);

await checkNomadBadge();
}

main().catch((err) => console.error(new Date(), "ERROR:", err));
53 changes: 53 additions & 0 deletions handlers/check-nomad-badge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Context, APIGatewayProxyResult, APIGatewayEvent } from "aws-lambda";
import { checkNomadBadge } from "../lib/check-nomad-badge.js";

export const handler = async (
event: APIGatewayEvent & {
campaignTagIds?: number[];
campaignBegins?: Date | string;
campaignEnds?: Date | string;
forceRun?: boolean;
},
context: Context
): Promise<APIGatewayProxyResult> => {
console.log(`Event:`, event);
console.log(`Context:`, context);

const { method, path } = (event?.requestContext as any)?.http || {};

Check warning on line 16 in handlers/check-nomad-badge.ts

View workflow job for this annotation

GitHub Actions / Build & Test

'method' is assigned a value but never used

Check warning on line 16 in handlers/check-nomad-badge.ts

View workflow job for this annotation

GitHub Actions / Build & Test

Unexpected any. Specify a different type
const { accept, origin }: { accept?: string; origin?: string } =
event?.headers || {};
if (
!(
event?.forceRun ||
(path === "/refresh" && accept?.includes("application/json"))
)
) {
return {
statusCode: 400,
body: JSON.stringify({
error:
"input error, call with POST /refresh with accept: application/json",
}),
};
}

const { campaignTagIds, campaignBegins, campaignEnds } = event;
const retBadges = await checkNomadBadge({
campaignTagIds,
campaignBegins,
campaignEnds,
});

return {
statusCode: 200,
body: JSON.stringify({ message: "done.", retBadges }),
...(origin &&
["https://matters-tech.static.observableusercontent.com"].includes(origin)
? {
headers: {
"Access-Control-Allow-Origin": origin,
},
}
: null),
};
};
Loading

0 comments on commit de3620e

Please sign in to comment.