DEV Community

Discussion on: Designing a better architecture for a Node.js API

Collapse
 
qleoz12 profile image
qleoz12

hey thanks in advance for this tutorial, but I download your repo from github and make this post with postman and dont works, stay Sending request.. and no work, dont return nothing, some advice could you give me ?

Collapse
 
pacheco profile image
Thiago Pacheco

Hi, are you sending a JSON body in your POST request? Do any errors show up in your terminal?
If you could, show me how you are making the request, please.

Collapse
 
qleoz12 profile image
qleoz12 • Edited

Dont worry master, my bad because Im begginer and I have no installed mongoDB for that no show nothing,any error or any response, after I installed mongo all works like a charm;otherwise can you help me with other thing? please?, im trying to do this...
import Controller from './Controller';
import PostService from "./../services/PostService";
import RecordService from "./../services/RecordService";
import Post from "./../models/Post";
import Record from "./../models/Record";
const postService = new PostService(
new Post().getInstance()
);

const recordService = new RecordService(
new Record().getInstance()
);

class PostController extends Controller {

constructor(service) {
super(service);
}

async insert(req, res)
{
console.log("usando overwrite");
let response = await this.postService.insert(req.body);
console.log("creando record");
let response2 = await this.recordService.insert({"title":response.slung,"status":"created","post": response });
console.log("creado "+response2);
if (response.error) return res.status(response.statusCode).send(response);
return res.status(201).send(response);
}
}

export default new PostController(postService);