UNPKG

@roadmanjs/couchset

Version:

A Couchbase roadman using CouchSet

88 lines 3.31 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPagination = exports.createUpdate = exports.CommonSchema = exports.CommonType = void 0; const type_graphql_1 = require("type-graphql"); const graphql_type_json_1 = __importDefault(require("graphql-type-json")); let CommonType = class CommonType { }; exports.CommonType = CommonType; __decorate([ (0, type_graphql_1.Field)(() => String, { nullable: true }) ], CommonType.prototype, "id", void 0); __decorate([ (0, type_graphql_1.Field)(() => String, { nullable: true }) ], CommonType.prototype, "env", void 0); __decorate([ (0, type_graphql_1.Field)(() => String, { nullable: true }) ], CommonType.prototype, "owner", void 0); __decorate([ (0, type_graphql_1.Field)(() => Date, { nullable: true }) ], CommonType.prototype, "createdAt", void 0); __decorate([ (0, type_graphql_1.Field)(() => Date, { nullable: true }) ], CommonType.prototype, "updatedAt", void 0); __decorate([ (0, type_graphql_1.Field)(() => Boolean, { nullable: true }) ], CommonType.prototype, "deleted", void 0); exports.CommonType = CommonType = __decorate([ (0, type_graphql_1.ObjectType)() ], CommonType); exports.CommonSchema = { id: String, env: String, owner: String, createdAt: Date, updatedAt: Date, deleted: Boolean, }; const createUpdate = async (args) => { const { model, id, data } = args; try { if (id) { // update await model.updateById(id, data); return data; } // create const createdItem = await model.create(data); return createdItem; } catch (error) { console.error(`error creating for ${model.collectionName}`, error); return null; } }; exports.createUpdate = createUpdate; /** * Creates a [className]Pagination ObjectType * @param c class * @returns */ const getPagination = (c) => { let Pagination = class Pagination { }; __decorate([ (0, type_graphql_1.Field)(() => [c], { nullable: true }) ], Pagination.prototype, "items", void 0); __decorate([ (0, type_graphql_1.Field)({ nullable: true }) ], Pagination.prototype, "hasNext", void 0); __decorate([ (0, type_graphql_1.Field)(() => graphql_type_json_1.default, { nullable: true }) ], Pagination.prototype, "params", void 0); Pagination = __decorate([ (0, type_graphql_1.ObjectType)(`${c.name}Pagination`) ], Pagination); return Pagination; }; exports.getPagination = getPagination; //# sourceMappingURL=common.model.js.map