11import { Request , Response } from "express" ;
2- import sequelize from "../../sequelize" ;
2+ import { Instrument } from "../../sequelize/models/instrument.model" ;
3+ import { Orchestra } from "../../sequelize/models/orchestra.model" ;
34import { getIdParam } from "../helpers" ;
45
5- const { models } = sequelize ;
6-
76export async function getAll ( req : Request , res : Response ) {
87 const orchestras =
98 "includeInstruments" in req . query
10- ? await models . orchestra . findAll ( { include : models . instrument } )
11- : await models . orchestra . findAll ( ) ;
9+ ? await Orchestra . findAll ( { include : Instrument } )
10+ : await Orchestra . findAll ( ) ;
1211 res . status ( 200 ) . json ( orchestras ) ;
1312}
1413
1514export async function getById ( req : Request , res : Response ) {
1615 const id = getIdParam ( req ) ;
1716 const orchestra =
1817 "includeInstruments" in req . query
19- ? await models . orchestra . findByPk ( id , { include : models . instrument } )
20- : await models . orchestra . findByPk ( id ) ;
18+ ? await Orchestra . findByPk ( id , { include : Instrument } )
19+ : await Orchestra . findByPk ( id ) ;
2120 if ( orchestra ) {
2221 res . status ( 200 ) . json ( orchestra ) ;
2322 } else {
@@ -33,7 +32,7 @@ export async function create(req: Request, res: Response) {
3332 `Bad request: ID should not be provided, since it is determined automatically by the database.`
3433 ) ;
3534 } else {
36- await models . orchestra . create ( req . body ) ;
35+ await Orchestra . create ( req . body ) ;
3736 res . status ( 201 ) . end ( ) ;
3837 }
3938}
@@ -43,9 +42,9 @@ export async function update(req: Request, res: Response) {
4342
4443 // We only accept an UPDATE request if the `:id` param matches the body `id`
4544 if ( req . body . id === id ) {
46- await models . orchestra . update ( req . body , {
45+ await Orchestra . update ( req . body , {
4746 where : {
48- id : id ,
47+ id,
4948 } ,
5049 } ) ;
5150 res . status ( 200 ) . end ( ) ;
@@ -60,9 +59,9 @@ export async function update(req: Request, res: Response) {
6059
6160export async function remove ( req : Request , res : Response ) {
6261 const id = getIdParam ( req ) ;
63- await models . orchestra . destroy ( {
62+ await Orchestra . destroy ( {
6463 where : {
65- id : id ,
64+ id,
6665 } ,
6766 } ) ;
6867 res . status ( 200 ) . end ( ) ;
0 commit comments