52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
"use strict";
|
|
import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
|
|
import { DbMixin } from "../mixins/db.mixin";
|
|
import Comic from "../models/comic.model";
|
|
import { walkFolder } from "../utils/uncompression.utils";
|
|
|
|
export default class ProductsService extends Service {
|
|
// @ts-ignore
|
|
public constructor(
|
|
public broker: ServiceBroker,
|
|
schema: ServiceSchema<{}> = { name: "import" }
|
|
) {
|
|
super(broker);
|
|
this.parseServiceSchema(
|
|
Service.mergeSchemas(
|
|
{
|
|
name: "import",
|
|
mixins: [DbMixin("comics", Comic)],
|
|
settings: {
|
|
// Available fields in the responses
|
|
fields: ["_id", "name", "quantity", "price"],
|
|
|
|
// Validator for the `create` & `insert` actions.
|
|
entityValidator: {
|
|
name: "string|min:3",
|
|
price: "number|positive",
|
|
},
|
|
},
|
|
hooks: {},
|
|
actions: {
|
|
walkFolders: {
|
|
rest: "POST /walkFolders",
|
|
params: {
|
|
basePathToWalk: "string",
|
|
},
|
|
async handler(
|
|
ctx: Context<{ basePathToWalk: string }>
|
|
) {
|
|
return await walkFolder(
|
|
ctx.params.basePathToWalk
|
|
);
|
|
},
|
|
},
|
|
},
|
|
methods: {},
|
|
},
|
|
schema
|
|
)
|
|
);
|
|
}
|
|
}
|