remoteMethod returns "no content" in loopback

371 views
Skip to first unread message

Miguel González Aravena

unread,
Aug 17, 2017, 2:13:02 AM8/17/17
to LoopbackJS
Hi everyone,

I want to build a "Chat" with loopback, but i can't forward because i'm stuck in this error. I use Google and Github and nothing.
This is the model called chat.json
{
  "name": "chats",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "ObjectId",
      "id": true
    },
    "exponente": {
      "type": "ObjectId",
      "required": true
    },
    "usuario": {
      "type": "ObjectId",
      "required": true
    },
    "mensajes": {
      "type": "array"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

And where is the remoteMethod is called chat.js (Both are in common/models/ directory)
'use strict';

module.exports = function(chats) {
  chats.open = function(exponente, usuario, cb) {
    chats.findOrCreate(
      { where: { exponente: exponente, usuario: usuario } },
      { exponente: exponente, usuario: usuario, mensajes: [] },
      function(err, instance, created) {
        console.log('Antes del callback');
        console.log(instance);
        cb(null, instance);
      }
    );
  };

  chats.remoteMethod('open', {
    http: { path: '/open', verb: 'post' },
    accepts: [
      { arg: 'exponente', type: 'string', required: true },
      { arg: 'usuario', type: 'string', required: true }
    ],
    returs: { arg: 'chat', type: 'object' },
    description: 'Find chat id of the document where you can send messages with exponent in the application.'
  });
};


In my model-config.json i have this config with Chat model.
[...]
"charlas": {
    "dataSource": "observatoriotui",
    "public": true
  },
[...]

When i do the query with Loopback page, didn't return a JSON. Response Body say "no content" with Status Code 204.

What can i do? I really need help with this. Sorry for my bad english, i'm Chilean.

Regards.

Raymond Feng

unread,
Aug 17, 2017, 2:23:05 AM8/17/17
to loopb...@googlegroups.com
findOrCreate should take the where object itself. The top level where property should be removed.

Sent from my iPhone 6 Plus
--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/0ea1e637-8fa8-4148-8aeb-2bf39e776a76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Miguel González Aravena

unread,
Aug 17, 2017, 2:28:51 AM8/17/17
to LoopbackJS
I follow this documentation:
https://apidocs.strongloop.com/loopback/#persistedmodel-findorcreate

Anyway, i tried to return a simple object and have the same Response body "no content" and i don't know why, even i habe other model Charlas with the similar code and this return JSON data.

Francois Laforge

unread,
Aug 17, 2017, 10:12:52 AM8/17/17
to LoopbackJS
Is a new chat instance being created in the database when none is found when you test your /open endpoint?

I noticed that the name of the model in model-config.json is not the same as in your chat.json file.  Is there a reason for this?

Miguel González Aravena

unread,
Aug 21, 2017, 8:06:49 PM8/21/17
to LoopbackJS
The problem was simple. I write 'returs' instead of 'returns' :D
Reply all
Reply to author
Forward
0 new messages