add course dropdown values
This commit is contained in:
@@ -8,7 +8,7 @@ export default class DropdownCtl {
|
||||
async getMeasurements() {
|
||||
try {
|
||||
const result = await DDInstance.getMeasurements();
|
||||
return new ControllerResponse<any[] | string>(
|
||||
return new ControllerResponse(
|
||||
((result !== null) ? StatusCode.OK : StatusCode.NotFound),
|
||||
result || "Measurement unit data not found",
|
||||
(result !== null)
|
||||
@@ -18,6 +18,19 @@ export default class DropdownCtl {
|
||||
}
|
||||
}
|
||||
|
||||
async getCourses() {
|
||||
try {
|
||||
const result = await DDInstance.getCourses();
|
||||
return new ControllerResponse(
|
||||
((result !== null) ? StatusCode.OK : StatusCode.NotFound),
|
||||
result || "Course data not found",
|
||||
(result !== null)
|
||||
);
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getByType(type: DropdownDataType) {
|
||||
switch (type) {
|
||||
case "measurement":
|
||||
|
||||
@@ -111,7 +111,13 @@ export default async function populate() {
|
||||
('gram', 'MEASUREMENTS', $1),
|
||||
('ounce', 'MEASUREMENTS', $1),
|
||||
('fluid ounce', 'MEASUREMENTS', $1),
|
||||
('pound', 'MEASUREMENTS', $1)
|
||||
('pound', 'MEASUREMENTS', $1),
|
||||
('breakfast', 'COURSE', $1),
|
||||
('lunch', 'COURSE', $1),
|
||||
('dinner', 'COURSE', $1),
|
||||
('dessert', 'COURSE', $1),
|
||||
('appetizer', 'COURSE', $1),
|
||||
('side', 'COURSE', $1)
|
||||
;
|
||||
`
|
||||
|
||||
|
||||
@@ -11,4 +11,15 @@ export default class Dropdown {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getCourses() {
|
||||
try {
|
||||
const statement = `SELECT * FROM recipin.dropdownVals WHERE datatype = 'COURSE'`;
|
||||
const result = await pool.query(statement);
|
||||
if (result.rows.length) return result.rows;
|
||||
return null;
|
||||
} catch (error: any) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,12 @@ export const dropdownValueRouter = (app: Express) => {
|
||||
try {
|
||||
switch (datatype) {
|
||||
case "measurement":
|
||||
const { code, data } = await DDInstance.getMeasurements();
|
||||
res.status(code).send(data);
|
||||
const measurements = await DDInstance.getMeasurements();
|
||||
res.status(measurements.code).send(measurements.data);
|
||||
break;
|
||||
case "course":
|
||||
const courses = await DDInstance.getCourses();
|
||||
res.status(courses.code).send(courses.data);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user