40 lines
883 B
TypeScript
40 lines
883 B
TypeScript
import { RequestHandler } from "express";
|
|
import { CampaignService } from "../../services/CampaignService";
|
|
|
|
export const getMany: RequestHandler = async (req, res, next) => {
|
|
try {
|
|
const campaignService = new CampaignService();
|
|
const campaigns = await campaignService.getAll();
|
|
|
|
return res.json({
|
|
ok: true,
|
|
data: campaigns,
|
|
});
|
|
} catch (error) {
|
|
return next(error);
|
|
}
|
|
};
|
|
|
|
export const create: RequestHandler = async (req, res, next) => {
|
|
try {
|
|
const { name, tokenId, maxDistributionAmount } = req.body;
|
|
if (!name || !tokenId || !maxDistributionAmount) {
|
|
throw new Error("Missing field(s).");
|
|
}
|
|
|
|
const campaignService = new CampaignService();
|
|
const campaign = await campaignService.create({
|
|
name,
|
|
tokenId,
|
|
maxDistributionAmount,
|
|
});
|
|
|
|
return res.json({
|
|
ok: true,
|
|
data: campaign,
|
|
});
|
|
} catch (error) {
|
|
return next(error);
|
|
}
|
|
};
|