extend newstellter config
This commit is contained in:
parent
7d36ed3121
commit
4180da5749
4 changed files with 51 additions and 4 deletions
|
@ -4,3 +4,7 @@ export interface SetNewsletterConfigCommand {
|
||||||
comTypeId: number;
|
comTypeId: number;
|
||||||
config: NewsletterConfigType;
|
config: NewsletterConfigType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DeleteNewsletterConfigCommand {
|
||||||
|
comTypeId: number;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { dataSource } from "../data-source";
|
import { dataSource } from "../data-source";
|
||||||
import { newsletterConfig } from "../entity/newsletterConfig";
|
import { newsletterConfig } from "../entity/newsletterConfig";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
import { SetNewsletterConfigCommand } from "./newsletterConfigCommand";
|
import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "./newsletterConfigCommand";
|
||||||
|
|
||||||
export default abstract class NewsletterConfigCommandHandler {
|
export default abstract class NewsletterConfigCommandHandler {
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,7 @@ export default abstract class NewsletterConfigCommandHandler {
|
||||||
* @param SetNewsletterConfigCommand
|
* @param SetNewsletterConfigCommand
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
*/
|
*/
|
||||||
static async setConfig(setNewsletterConfig: SetNewsletterConfigCommand): Promise<number> {
|
static async set(setNewsletterConfig: SetNewsletterConfigCommand): Promise<number> {
|
||||||
return await dataSource
|
return await dataSource
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.insert()
|
.insert()
|
||||||
|
@ -27,4 +27,21 @@ export default abstract class NewsletterConfigCommandHandler {
|
||||||
throw new InternalException("Failed setting newsletterConfig", err);
|
throw new InternalException("Failed setting newsletterConfig", err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @description delete newsletterConfig
|
||||||
|
* @param number
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async delete(deleteNewsletterConfig: DeleteNewsletterConfigCommand): Promise<void> {
|
||||||
|
return await dataSource
|
||||||
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(newsletterConfig)
|
||||||
|
.where("comTypeId = :comTypeId", { comTypeId: deleteNewsletterConfig.comTypeId })
|
||||||
|
.execute()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new InternalException("Failed setting newsletterConfig", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Request, Response } from "express";
|
||||||
import NewsletterConfigService from "../../service/newsletterConfigService";
|
import NewsletterConfigService from "../../service/newsletterConfigService";
|
||||||
import NewsletterConfigFactory from "../../factory/admin/newsletterConfig";
|
import NewsletterConfigFactory from "../../factory/admin/newsletterConfig";
|
||||||
import NewsletterConfigCommandHandler from "../../command/newsletterConfigCommandHandler";
|
import NewsletterConfigCommandHandler from "../../command/newsletterConfigCommandHandler";
|
||||||
import { SetNewsletterConfigCommand } from "../../command/newsletterConfigCommand";
|
import { DeleteNewsletterConfigCommand, SetNewsletterConfigCommand } from "../../command/newsletterConfigCommand";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all newsletterConfigs
|
* @description get all newsletterConfigs
|
||||||
|
@ -43,7 +43,24 @@ export async function setNewsletterConfig(req: Request, res: Response): Promise<
|
||||||
comTypeId,
|
comTypeId,
|
||||||
config,
|
config,
|
||||||
};
|
};
|
||||||
let id = await NewsletterConfigCommandHandler.setConfig(createNewsletterConfig);
|
let id = await NewsletterConfigCommandHandler.set(createNewsletterConfig);
|
||||||
|
|
||||||
res.send(id);
|
res.send(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description delete award
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function deleteNewsletterConfig(req: Request, res: Response): Promise<any> {
|
||||||
|
const comTypeId = parseInt(req.params.comTypeId);
|
||||||
|
|
||||||
|
let deleteNewsletterConfig: DeleteNewsletterConfigCommand = {
|
||||||
|
comTypeId: comTypeId,
|
||||||
|
};
|
||||||
|
await NewsletterConfigCommandHandler.delete(deleteNewsletterConfig);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
import {
|
import {
|
||||||
|
deleteNewsletterConfig,
|
||||||
getAllNewsletterConfigs,
|
getAllNewsletterConfigs,
|
||||||
getNewsletterConfigById,
|
getNewsletterConfigById,
|
||||||
setNewsletterConfig,
|
setNewsletterConfig,
|
||||||
|
@ -24,4 +25,12 @@ router.put(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.delete(
|
||||||
|
"/:comTypeId",
|
||||||
|
PermissionHelper.passCheckMiddleware("create", "settings", "newsletter_config"),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
|
await deleteNewsletterConfig(req, res);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Reference in a new issue