im trying to sort out a get function for my api and i have run into this error@ Declaration or statement expected.ts(1128) its in the second else statement.
I have edited the code and taken an oid validation out of it it might be due to this im not too sure.
I’ll have both of the codes before and after the editing in the question.
I edited the function because im trying to get the get request to work without having to have the user to input the oid(object id).
Before:
async function getComments(req) {
let status = 500, data = null;
try {
const oid = req.query.oid;
if (oid
&& oid.length > 0 && oid.length <= 32
&& oid.match(/^[a-z0-9]+$/i)) {
const sql = 'SELECT * FROM products';
const rows = await db.query(sql, [oid]);
if (rows) {
status = 200;
data = {
'oid': oid,
'productName': rows,
'productCondition': rows,
'productDescription': rows,
'productLocation': rows,
};
} else {
status = 204;
}
} else {
status = 400;
}
} catch (e) {
console.error(e);
}
return { status, data };
}
After:
async function getComments(req) {
let status = 500, data = null;
try {
const sql = 'SELECT * FROM products';
const rows = await db.query(sql, [oid]);
if (rows) {
status = 200;
data = {
'oid': oid,
'productName': rows,
'productCondition': rows,
'productDescription': rows,
'productLocation': rows,
};
} else {
status = 204;
} else {
status = 400;
}
} catch (e) {
console.error(e);
}
return { status, data };
}