I have successfully implemented CRUD operations using TSOA in TypeScript. However, I am facing an issue where I receive an empty array when making HTTP requests, despite adding data to the 'Livraison' table in MongoDB.
https://i.sstatic.net/7IWTL.png
- Below is my model definition:
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)
- Here is my controller implementation:
@Route("/livraison")
@Tags("Livraison")
export class LivraisonController extends Controller {
@Get('/')
async getAllLivraison() : Promise<any> {
const result = await livraisonModel.find({});
return {
error: null,
data: result,
};
}
}
- And, this is how my routing is set up:
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;