Search code examples
typescriptpostmanopenapitsoa

tsoa typescript empty array in response in postman


i have created crud with tsoa typescript but when i request any http request i get an empty array and of course i added data to table livraison in mongodb

empty array

  • This is my model.ts
export interface ILivraison extends Document {
  code: String;
  image1: String;
  image2: String;
  image3 : String;
}
const LivraisonSchema: Schema = new Schema({
    code: {
    type: String,
    required: true,
  },
  image1: {
    type: String,
    required: true,
  },
  image2: {
    type: String,
    required: true,
  },
  image3: {
    type: String,
    required: true,
  },
})
export default mongoose.model < ILivraison > ("Livraison", LivraisonSchema)
  • This is my controller.ts
@Route("/livraison")
@Tags("Livraison")
export class LivraisonController extends Controller {


@Get('/')
async getAllLivraison()  : Promise<any> {
    const result = await livraisonModel.find({});
    return {
      error: null,
      data: result,
    };
}
}
  • This is my Route.ts:
const route: Router = Router();

route.get('/',async (req: Request, res: Response) => {
  const controller = new LivraisonController();
  const result = await controller.getAllLivraison();
  const { error, data } = result;
  if (error) {
    res.status(400).json(error);
    return;
  }
  res.status(200).send(data);
});

export default route;

Solution

  • From the above image, request url is wrong. Edit url and invoke again.