当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript class-transformer.classToPlain函数代码示例

本文整理汇总了TypeScript中class-transformer.classToPlain函数的典型用法代码示例。如果您正苦于以下问题:TypeScript classToPlain函数的具体用法?TypeScript classToPlain怎么用?TypeScript classToPlain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了classToPlain函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: newWorkflow

	/**
	 * Creates a new workflow under a given playbook.
	 * @param playbookId ID of the playbook the new workflow should be added under
	 * @param workflow Workflow to be saved
	 */
	newWorkflow(playbookId: string, workflow: Workflow): Promise<Workflow> {
		workflow.playbook_id = playbookId;

		return this.http.post('/api/workflows', classToPlain(workflow))
			.toPromise()
			.then((data) => plainToClass(Workflow, data))
			.catch(this.utils.handleResponseError);
	}
开发者ID:iadgov,项目名称:WALKOFF,代码行数:13,代码来源:playbook.service.ts

示例2: addWorkflowToQueue

	/**
	 * Asyncronously adds a workflow (by ID) to the queue to be executed.
	 * Returns the new workflow status for the workflow execution.
	 * @param workflowId Workflow Id to queue
	 */
	addWorkflowToQueue(workflow_id: string, variables: EnvironmentVariable[] = []): Promise<WorkflowStatus> {
		let data: any = { workflow_id };
		if (variables.length > 0) data.environment_variables = classToPlain(variables);

		return this.http.post('api/workflowqueue', data)
			.toPromise()
			.then((data: object) => plainToClass(WorkflowStatus, data))
			.catch(this.utils.handleResponseError);
	}
开发者ID:iadgov,项目名称:WALKOFF,代码行数:14,代码来源:execution.service.ts

示例3: classToPlain

 transform<E, D>(value: E, newType: ClassType<D>): D {
     const plain = classToPlain(value);
     return plainToClass(newType, plain);
 }
开发者ID:pschild,项目名称:image-management-tool,代码行数:4,代码来源:dto-transformer.service.ts

示例4: handleSuccess

    handleSuccess(result: any, action: ActionMetadata, options: ActionCallbackOptions): void {

        if (this.useClassTransformer && result && result instanceof Object) {
            const options = action.responseClassTransformOptions || this.classToPlainTransformOptions;
            result = classToPlain(result, options);
        }

        const response: any = options.response;
        const isResultUndefined = result === undefined;
        const isResultNull = result === null;
        const isResultEmpty = isResultUndefined || isResultNull || result === false || result === "";

        // set http status
        if (action.undefinedResultCode && isResultUndefined) {
            response.status = action.undefinedResultCode;

        } else if (action.nullResultCode && isResultNull) {
            response.status = action.nullResultCode;

        } else if (action.emptyResultCode && isResultEmpty) {
            response.status = action.emptyResultCode;

        } else if (action.successHttpCode) {
            response.status = action.successHttpCode;
        }

        // apply http headers
        Object.keys(action.headers).forEach(name => {
            response.set(name, action.headers[name]);
        });

        if (action.redirect) { // if redirect is set then do it
            response.redirect(action.redirect);
            options.next();
            // options.resolver();

        } else if (action.renderedTemplate) { // if template is set then render it // todo: not working in koa
            const renderOptions = result && result instanceof Object ? result : {};

            this.koa.use(async function (ctx: any, next: any) {
                await ctx.render(action.renderedTemplate, renderOptions);
            });

            options.next();
        } else if (result !== undefined || action.undefinedResultCode) { // send regular result
            if (result === null || (result === undefined && action.undefinedResultCode)) {

                if (action.isJsonTyped) {
                    response.body = null;
                } else {
                    response.body = null;
                }

                // todo: duplication. we make it here because after we set null to body koa seems overrides status
                if (action.nullResultCode) {
                    response.status = action.nullResultCode;

                } else if (action.emptyResultCode) {
                    response.status = action.emptyResultCode;

                } else if (result === undefined && action.undefinedResultCode) {
                    response.status = action.undefinedResultCode;
                }

                options.next();
            } else {
                if (action.isJsonTyped) {
                    response.body = result;
                } else {
                    response.body = String(result);
                }
                options.next();
            }
            // options.resolver();

        } else {
            options.next();
            // options.resolver();
        }
    }
开发者ID:alexproca,项目名称:routing-controllers,代码行数:80,代码来源:KoaDriver.ts

示例5: saveWorkflow

	/**
	 * Saves the data of a given workflow specified under a given playbook.
	 * @param workflow Data to be saved under the workflow (actions, etc.)
	 */
	saveWorkflow(workflow: Workflow): Promise<Workflow> {
		return this.http.put('/api/workflows', classToPlain(workflow))
			.toPromise()
			.then((data) => plainToClass(Workflow, data))
			.catch(this.utils.handleResponseError);
	}
开发者ID:iadgov,项目名称:WALKOFF,代码行数:10,代码来源:playbook.service.ts

示例6: handleSuccess

    /**
     * Defines an algorithm of how to handle success result of executing controller action.
     */
    handleSuccess(result: any, action: ActionMetadata, options: ActionCallbackOptions): void {
        if (this.useClassTransformer && result && result instanceof Object) {
            const options = action.responseClassTransformOptions || this.classToPlainTransformOptions;
            result = classToPlain(result, options);
        }

        const response: any = options.response;
        const isResultUndefined = result === undefined;
        const isResultNull = result === null;
        const isResultEmpty = isResultUndefined || isResultNull || result === false || result === "";

        // set http status
        if (action.undefinedResultCode && isResultUndefined) {
            response.status(action.undefinedResultCode);

        } else if (action.nullResultCode && isResultNull) {
            response.status(action.nullResultCode);

        } else if (action.emptyResultCode && isResultEmpty) {
            response.status(action.emptyResultCode);

        } else if (action.successHttpCode) {
            response.status(action.successHttpCode);
        }

        // apply http headers
        Object.keys(action.headers).forEach(name => {
            response.header(name, action.headers[name]);
        });

        if (action.redirect) { // if redirect is set then do it
            response.redirect(action.redirect);
            options.next();

        } else if (action.renderedTemplate) { // if template is set then render it
            const renderOptions = result && result instanceof Object ? result : {};

            this.express.render(action.renderedTemplate, renderOptions, (err: any, html: string) => {
                if (err && action.isJsonTyped) {
                    // response.json(err);
                    return options.next(err);

                } else if (err && !action.isJsonTyped) {
                    // response.send(err);
                    return options.next(err);

                } else if (html) {
                    response.send(html);
                }
                options.next();
            });

        } else if (result !== undefined || action.undefinedResultCode) { // send regular result
            if (result === null || (result === undefined && action.undefinedResultCode)) {
                if (result === null && !action.nullResultCode && !action.emptyResultCode) {
                    response.status(204);
                }

                if (action.isJsonTyped) {
                    response.json();
                } else {
                    response.send();
                }
                options.next();
            } else {
                if (action.isJsonTyped) {
                    response.json(result);
                } else {
                    response.send(String(result));
                }
                options.next();
            }

        } else {
            options.next();
        }
    }
开发者ID:alexproca,项目名称:routing-controllers,代码行数:80,代码来源:ExpressDriver.ts


注:本文中的class-transformer.classToPlain函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。