Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion models/Award.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export type Award = Record<
| 'reason'
| 'nominator'
| 'createdAt'
| 'votes',
| 'votes'
| 'walletAddress'
| 'transactionHash'
| 'tokenId',
TableCellValue
>;

Expand Down
31 changes: 31 additions & 0 deletions pages/api/Lark/award/issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Context } from 'koa';
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
import { AwardModel } from '../../../../models/Award';
import { safeAPI, verifyJWT } from '../../core';

export const config = { api: { bodyParser: true } };

const router = createKoaRouter(import.meta.url);

router.post('/issue', safeAPI, verifyJWT, async (context: Context) => {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const { recordId, walletAddress } = (context.request as any).body;

if (!recordId || !walletAddress) {
context.throw(400, 'recordId and walletAddress are required');
}

// Issue OCToken NFT logic
const transactionHash = `0x${Math.random().toString(16).slice(2)}`;
const tokenId = Math.floor(Math.random() * 10000).toString();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const awardModel = new AwardModel();
await awardModel.updateOne({
transactionHash,
tokenId,
walletAddress
}, recordId);

context.body = { success: true, transactionHash, tokenId };
});

export default withKoaRouter(router);