Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

find code ? #61

Closed
nlefebvre1410 opened this issue Jul 9, 2017 · 2 comments
Closed

find code ? #61

nlefebvre1410 opened this issue Jul 9, 2017 · 2 comments

Comments

@nlefebvre1410
Copy link

nlefebvre1410 commented Jul 9, 2017

Hello,
I created a customer service and it leaves me that:

{
"status": 200,
"data": [
{
"code": "wNyPGOPGJz",
"createdAt": "2017-07-08T12:46:42.341Z",
"updatedAt": "2017-07-08T12:46:42.341Z"
}
]
}

instead of :

{
"status": 200,
"data": [
{
"_id": 1,
"updatedAt": "2017-07-08T12:46:42.341Z",
"createdAt": "2017-07-08T12:46:42.341Z",
"entete": "Ryan-Hilpert LLC",
"contact": "Laverne Grady",
"email": "jackietremblay44@yahoo.com",
"ville": "Eritrea",
"phone": "014.460.2206 x07079",
"__v": 0,
"cp": "52909",
"code": "wNyPGOPGJz",
"id": "1"
},
]

To get the result I remove the function this.toJSON

Here is the complete file:

"use strict";

let logger 		= require("../../../core/logger");
let config 		= require("../../../config");
let C 	 		= require("../../../core/constants");
let _			= require("lodash");
let Client		= require("./models/clients");

module.exports = {
	settings: {
		name: "clients",
		version: 1,
		namespace: "clients",
		rest: true,
		ws: true,
		graphql: true,
		permission: C.PERM_LOGGEDIN,
		role: "user",
		collection: Client,

		modelPropFilter: "code type address name description status lastCommunication createdAt updatedAt"
	},

	actions: {
		find: {
			cache: true,
			handler(ctx) {
				let filter = {};
				
				let query = Client.find(filter);

				return ctx.queryPageSort(query).exec().then( (docs) => {
					return this.toJSON(docs);
				})
					.then((json) => {
						return this.populateModels(json);
					});
			}
		},
		// return a model by ID
		get: {
			cache: true,
			handler(ctx) {
				ctx.assertModelIsExist(ctx.t("app:DeviceNotFound"));
				console.log(ctx.model)
				return Promise.resolve(ctx.model);
			}
		},

		create(ctx) {
			this.validateParams(ctx, true);

			let client = new Client({
				entete: ctx.params.entete,
				contact: ctx.params.contact,
				email: ctx.params.email,
				address: ctx.params.address,
				cp: ctx.params.cp,
				ville: ctx.params.ville,
				phone: ctx.params.phone
			});

			return client.save()
			.then((doc) => {
				return this.toJSON(doc);
			})
			.then((json) => {
				return this.populateModels(json);
			})
			.then((json) => {
				this.notifyModelChanges(ctx, "created", json);
				return json;
			});
		}
	},

	methods: {
		},

		graphql: {
			query: `
			clients(limit: Int, offset: Int, sort: String): [Client]
			client(code: String): Client
		`,
			types: `
			type Client {
				entete: String!
				contact: String
				email: String
				cp: Int
				ville: String
				phone: Int
			}
		`,

			mutation: `
			clientCreate(	entete: String!, contact: String, email: String, cp: Int, ville: String, phone: Int): Client
		`,

			resolvers: {
				Query: {
					clients: "find",
					client: "get"
				},

				Mutation: {
					clientCreate: "create"
				}
			}
		}
};
@nlefebvre1410
Copy link
Author

Sorry i found

@icebob
Copy link
Owner

icebob commented Jul 9, 2017

👍

@icebob icebob closed this as completed Jul 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants