event details for event page
This commit is contained in:
18
server/connections/apiKey.js
Normal file
18
server/connections/apiKey.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const axios = require("axios");
|
||||
|
||||
// Adam's personal API key server access
|
||||
// Requires connection to private tailscale subnet.
|
||||
// no abusing of my api keys or i abuse you 🔫
|
||||
async function getApiKey(serviceUrl) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
"http://mommy.rya-orfe.ts.net:8069/" + serviceUrl
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error retrieving API key:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getApiKey };
|
||||
@@ -1,21 +1,10 @@
|
||||
const axios = require("axios");
|
||||
const senderEmail = "ecoconnect@trial-ynrw7gy0qxol2k8e.mlsender.net";
|
||||
|
||||
async function getApiKey() {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
"http://mommy.rya-orfe.ts.net:8069/mailersend_api_key"
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error retrieving API key:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
const { getApiKey } = require("./apiKey");
|
||||
|
||||
async function sendEmail(recipientEmail, title, content) {
|
||||
try {
|
||||
const apiKey = await getApiKey();
|
||||
const apiKey = await getApiKey("mailersend_api_key");
|
||||
const response = await axios.post(
|
||||
"https://api.mailersend.com/v1/email",
|
||||
{
|
||||
|
||||
20
server/connections/openai.js
Normal file
20
server/connections/openai.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const OpenAI = require("openai");
|
||||
const { getApiKey } = require("./apiKey");
|
||||
|
||||
async function openAiChatCompletion(query, systemPrompt) {
|
||||
const openai = new OpenAI({ apiKey: await getApiKey("openai_api_key") });
|
||||
const completion = await openai.chat.completions.create({
|
||||
messages: [
|
||||
{ role: "system", content: systemPrompt },
|
||||
{ role: "user", content: query },
|
||||
],
|
||||
model: "gpt-4o-mini",
|
||||
});
|
||||
|
||||
let response = completion.choices[0].message.content;
|
||||
console.log(response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
module.exports = { openAiChatCompletion };
|
||||
@@ -37,6 +37,9 @@ app.use("/schedule", schedulesRoute);
|
||||
const HBCformRoute = require("./routes/hbcform");
|
||||
app.use("/hbcform", HBCformRoute);
|
||||
|
||||
const connections = require("./routes/connections");
|
||||
app.use("/connections", connections);
|
||||
|
||||
db.sequelize
|
||||
.sync({ alter: true })
|
||||
.then(() => {
|
||||
|
||||
@@ -26,6 +26,10 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
avgBill: {
|
||||
type: DataTypes.DECIMAL(7, 2),
|
||||
allowNull: false
|
||||
},
|
||||
ebPicture: {
|
||||
type: DataTypes.BLOB("long"),
|
||||
allowNull: true,
|
||||
|
||||
@@ -17,9 +17,14 @@ module.exports = (sequelize, DataTypes) => {
|
||||
content: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false
|
||||
}
|
||||
},
|
||||
userId: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
},
|
||||
}, {
|
||||
tableName: 'posts'
|
||||
});
|
||||
|
||||
return Post;
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
"multer": "1.4.5-lts.1",
|
||||
"mysql2": "^3.10.1",
|
||||
"nodemon": "^3.1.3",
|
||||
"openai": "^4.53.2",
|
||||
"sequelize": "^6.37.3",
|
||||
"sharp": "^0.33.4",
|
||||
"uuid": "^10.0.0",
|
||||
|
||||
220
server/pnpm-lock.yaml
generated
220
server/pnpm-lock.yaml
generated
@@ -4,52 +4,52 @@ settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
argon2:
|
||||
specifier: ^0.40.3
|
||||
version: 0.40.3
|
||||
axios:
|
||||
specifier: ^1.7.2
|
||||
version: 1.7.2
|
||||
bad-words:
|
||||
specifier: ^3.0.4
|
||||
version: 3.0.4
|
||||
cors:
|
||||
specifier: ^2.8.5
|
||||
version: 2.8.5
|
||||
dotenv:
|
||||
specifier: ^16.4.5
|
||||
version: 16.4.5
|
||||
express:
|
||||
specifier: ^4.19.2
|
||||
version: 4.19.2
|
||||
jsonwebtoken:
|
||||
specifier: ^9.0.2
|
||||
version: 9.0.2
|
||||
multer:
|
||||
specifier: 1.4.5-lts.1
|
||||
version: 1.4.5-lts.1
|
||||
mysql2:
|
||||
specifier: ^3.10.1
|
||||
version: 3.10.1
|
||||
nodemon:
|
||||
specifier: ^3.1.3
|
||||
version: 3.1.3
|
||||
sequelize:
|
||||
specifier: ^6.37.3
|
||||
version: 6.37.3(mysql2@3.10.1)
|
||||
sharp:
|
||||
specifier: ^0.33.4
|
||||
version: 0.33.4
|
||||
uuid:
|
||||
specifier: ^10.0.0
|
||||
version: 10.0.0
|
||||
yup:
|
||||
specifier: ^1.4.0
|
||||
version: 1.4.0
|
||||
dependencies:
|
||||
argon2:
|
||||
specifier: ^0.40.3
|
||||
version: 0.40.3
|
||||
axios:
|
||||
specifier: ^1.7.2
|
||||
version: 1.7.2
|
||||
bad-words:
|
||||
specifier: ^3.0.4
|
||||
version: 3.0.4
|
||||
cors:
|
||||
specifier: ^2.8.5
|
||||
version: 2.8.5
|
||||
dotenv:
|
||||
specifier: ^16.4.5
|
||||
version: 16.4.5
|
||||
express:
|
||||
specifier: ^4.19.2
|
||||
version: 4.19.2
|
||||
jsonwebtoken:
|
||||
specifier: ^9.0.2
|
||||
version: 9.0.2
|
||||
multer:
|
||||
specifier: 1.4.5-lts.1
|
||||
version: 1.4.5-lts.1
|
||||
mysql2:
|
||||
specifier: ^3.10.1
|
||||
version: 3.10.1
|
||||
nodemon:
|
||||
specifier: ^3.1.3
|
||||
version: 3.1.3
|
||||
openai:
|
||||
specifier: ^4.53.2
|
||||
version: 4.53.2
|
||||
sequelize:
|
||||
specifier: ^6.37.3
|
||||
version: 6.37.3(mysql2@3.10.1)
|
||||
sharp:
|
||||
specifier: ^0.33.4
|
||||
version: 0.33.4
|
||||
uuid:
|
||||
specifier: ^10.0.0
|
||||
version: 10.0.0
|
||||
yup:
|
||||
specifier: ^1.4.0
|
||||
version: 1.4.0
|
||||
|
||||
packages:
|
||||
|
||||
@@ -179,17 +179,44 @@ packages:
|
||||
'@types/ms@0.7.34':
|
||||
resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==}
|
||||
|
||||
'@types/node@20.14.6':
|
||||
/@types/node-fetch@2.6.11:
|
||||
resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}
|
||||
dependencies:
|
||||
'@types/node': 20.14.6
|
||||
form-data: 4.0.0
|
||||
dev: false
|
||||
|
||||
/@types/node@18.19.42:
|
||||
resolution: {integrity: sha512-d2ZFc/3lnK2YCYhos8iaNIYu9Vfhr92nHiyJHRltXWjXUBjEE+A4I58Tdbnw4VhggSW+2j5y5gTrLs4biNnubg==}
|
||||
dependencies:
|
||||
undici-types: 5.26.5
|
||||
dev: false
|
||||
|
||||
/@types/node@20.14.6:
|
||||
resolution: {integrity: sha512-JbA0XIJPL1IiNnU7PFxDXyfAwcwVVrOoqyzzyQTyMeVhBzkJVMSkC1LlVsRQ2lpqiY4n6Bb9oCS6lzDKVQxbZw==}
|
||||
|
||||
'@types/validator@13.12.0':
|
||||
resolution: {integrity: sha512-nH45Lk7oPIJ1RVOF6JgFI6Dy0QpHEzq4QecZhvguxYPDwT8c93prCMqAtiIttm39voZ+DDR+qkNnMpJmMBRqag==}
|
||||
|
||||
accepts@1.3.8:
|
||||
/abort-controller@3.0.0:
|
||||
resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==}
|
||||
engines: {node: '>=6.5'}
|
||||
dependencies:
|
||||
event-target-shim: 5.0.1
|
||||
dev: false
|
||||
|
||||
/accepts@1.3.8:
|
||||
resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
anymatch@3.1.3:
|
||||
/agentkeepalive@4.5.0:
|
||||
resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==}
|
||||
engines: {node: '>= 8.0.0'}
|
||||
dependencies:
|
||||
humanize-ms: 1.2.1
|
||||
dev: false
|
||||
|
||||
/anymatch@3.1.3:
|
||||
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
@@ -376,7 +403,12 @@ packages:
|
||||
resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
express@4.19.2:
|
||||
/event-target-shim@5.0.1:
|
||||
resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==}
|
||||
engines: {node: '>=6'}
|
||||
dev: false
|
||||
|
||||
/express@4.19.2:
|
||||
resolution: {integrity: sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==}
|
||||
engines: {node: '>= 0.10.0'}
|
||||
|
||||
@@ -397,11 +429,23 @@ packages:
|
||||
debug:
|
||||
optional: true
|
||||
|
||||
form-data@4.0.0:
|
||||
/form-data-encoder@1.7.2:
|
||||
resolution: {integrity: sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==}
|
||||
dev: false
|
||||
|
||||
/form-data@4.0.0:
|
||||
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
forwarded@0.2.0:
|
||||
/formdata-node@4.4.1:
|
||||
resolution: {integrity: sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==}
|
||||
engines: {node: '>= 12.20'}
|
||||
dependencies:
|
||||
node-domexception: 1.0.0
|
||||
web-streams-polyfill: 4.0.0-beta.3
|
||||
dev: false
|
||||
|
||||
/forwarded@0.2.0:
|
||||
resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==}
|
||||
engines: {node: '>= 0.6'}
|
||||
|
||||
@@ -454,7 +498,13 @@ packages:
|
||||
resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==}
|
||||
engines: {node: '>= 0.8'}
|
||||
|
||||
iconv-lite@0.4.24:
|
||||
/humanize-ms@1.2.1:
|
||||
resolution: {integrity: sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==}
|
||||
dependencies:
|
||||
ms: 2.1.3
|
||||
dev: false
|
||||
|
||||
/iconv-lite@0.4.24:
|
||||
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
@@ -615,7 +665,24 @@ packages:
|
||||
resolution: {integrity: sha512-ipO7rsHEBqa9STO5C5T10fj732ml+5kLN1cAG8/jdHd56ldQeGj3Q7+scUS+VHK/qy1zLEwC4wMK5+yM0btPvw==}
|
||||
engines: {node: ^18 || ^20 || >= 21}
|
||||
|
||||
node-gyp-build@4.8.1:
|
||||
/node-domexception@1.0.0:
|
||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||
engines: {node: '>=10.5.0'}
|
||||
dev: false
|
||||
|
||||
/node-fetch@2.7.0:
|
||||
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
||||
engines: {node: 4.x || >=6.0.0}
|
||||
peerDependencies:
|
||||
encoding: ^0.1.0
|
||||
peerDependenciesMeta:
|
||||
encoding:
|
||||
optional: true
|
||||
dependencies:
|
||||
whatwg-url: 5.0.0
|
||||
dev: false
|
||||
|
||||
/node-gyp-build@4.8.1:
|
||||
resolution: {integrity: sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==}
|
||||
hasBin: true
|
||||
|
||||
@@ -639,7 +706,22 @@ packages:
|
||||
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
|
||||
engines: {node: '>= 0.8'}
|
||||
|
||||
parseurl@1.3.3:
|
||||
/openai@4.53.2:
|
||||
resolution: {integrity: sha512-ohYEv6OV3jsFGqNrgolDDWN6Ssx1nFg6JDJQuaBFo4SL2i+MBoOQ16n2Pq1iBF5lH1PKnfCIOfqAGkmzPvdB9g==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
'@types/node': 18.19.42
|
||||
'@types/node-fetch': 2.6.11
|
||||
abort-controller: 3.0.0
|
||||
agentkeepalive: 4.5.0
|
||||
form-data-encoder: 1.7.2
|
||||
formdata-node: 4.4.1
|
||||
node-fetch: 2.7.0
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
dev: false
|
||||
|
||||
/parseurl@1.3.3:
|
||||
resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==}
|
||||
engines: {node: '>= 0.8'}
|
||||
|
||||
@@ -1629,7 +1711,14 @@ snapshots:
|
||||
|
||||
touch@3.1.1: {}
|
||||
|
||||
tslib@2.6.3:
|
||||
/tr46@0.0.3:
|
||||
resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
|
||||
dev: false
|
||||
|
||||
/tslib@2.6.3:
|
||||
resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==}
|
||||
requiresBuild: true
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
type-fest@2.19.0: {}
|
||||
@@ -1659,7 +1748,24 @@ snapshots:
|
||||
|
||||
vary@1.1.2: {}
|
||||
|
||||
wkx@0.5.0:
|
||||
/web-streams-polyfill@4.0.0-beta.3:
|
||||
resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}
|
||||
engines: {node: '>= 14'}
|
||||
dev: false
|
||||
|
||||
/webidl-conversions@3.0.1:
|
||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
dev: false
|
||||
|
||||
/whatwg-url@5.0.0:
|
||||
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
|
||||
dependencies:
|
||||
tr46: 0.0.3
|
||||
webidl-conversions: 3.0.1
|
||||
dev: false
|
||||
|
||||
/wkx@0.5.0:
|
||||
resolution: {integrity: sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==}
|
||||
dependencies:
|
||||
'@types/node': 20.14.6
|
||||
|
||||
|
||||
40
server/routes/connections.js
Normal file
40
server/routes/connections.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const express = require("express");
|
||||
const { openAiChatCompletion } = require("../connections/openai");
|
||||
const { validateToken } = require("../middlewares/auth");
|
||||
const router = express.Router();
|
||||
|
||||
const nlsPrompt = `
|
||||
"/": home
|
||||
"/springboard": user dashboard
|
||||
"/manage-account": user account management
|
||||
"/events": events
|
||||
"/karang-guni-schedules": browse slots
|
||||
"/home-bill-contest": participate in contest & earn vouchers
|
||||
"/home-bill-contest/new-submission": submit bill
|
||||
"/community-posts": show posts
|
||||
"/community-posts/create": create post
|
||||
|
||||
based on input, provide appropriate route closest to fulfilling user's needs
|
||||
If none matches user query, return empty route.
|
||||
in following format:
|
||||
|
||||
{"route": "<appropriate route>"}
|
||||
`;
|
||||
|
||||
async function naturalLanguageSearch(userQuery) {
|
||||
return await openAiChatCompletion(userQuery, nlsPrompt);
|
||||
}
|
||||
|
||||
router.get("/nls/:query", validateToken, async (req, res) => {
|
||||
let data = req.params.query;
|
||||
console.log(data);
|
||||
try {
|
||||
let chatResponse = await naturalLanguageSearch(data);
|
||||
res.json({ response: chatResponse });
|
||||
} catch (error) {
|
||||
console.error("Error with AI:", error);
|
||||
res.status(500).json({ message: "Internal Server Error" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -23,6 +23,7 @@ router.post("/", upload.fields([
|
||||
waterBill: yup.number().positive().required(),
|
||||
totalBill: yup.number().positive().required(),
|
||||
noOfDependents: yup.number().integer().positive().required(),
|
||||
avgBill: yup.number().positive().required(),
|
||||
});
|
||||
try {
|
||||
data = await validationSchema.validate(data, { abortEarly: false });
|
||||
@@ -48,6 +49,7 @@ router.get("/", async (req, res) => {
|
||||
{ waterBill: { [Op.like]: `%${search}%` } },
|
||||
{ totalBill: { [Op.like]: `%${search}%` } },
|
||||
{ noOfDependents: { [Op.like]: `%${search}%` } },
|
||||
{ avgBill: { [Op.like]: `%${search}%` } },
|
||||
];
|
||||
}
|
||||
let list = await HBCform.findAll({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { Post } = require('../models');
|
||||
const { Post, User } = require('../models');
|
||||
const { Op, where } = require("sequelize");
|
||||
const yup = require("yup");
|
||||
const multer = require("multer");
|
||||
@@ -56,10 +56,14 @@ router.post("/", async (req, res) => {
|
||||
// });
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
let condition = {};
|
||||
let condition = {
|
||||
where: {},
|
||||
order: [['createdAt', 'DESC']]
|
||||
};
|
||||
|
||||
let search = req.query.search;
|
||||
if (search) {
|
||||
condition[Op.or] = [
|
||||
condition.where[Op.or] = [
|
||||
{ title: { [Op.like]: `%${search}%` } },
|
||||
{ content: { [Op.like]: `%${search}%` } }
|
||||
];
|
||||
@@ -67,11 +71,7 @@ router.get("/", async (req, res) => {
|
||||
// You can add condition for other columns here
|
||||
// e.g. condition.columnName = value;
|
||||
|
||||
let list = await Post.findAll({
|
||||
where: condition,
|
||||
// order option takes an array of items. These items are themselves in the form of [column, direction]
|
||||
order: [['createdAt', 'DESC']]
|
||||
});
|
||||
let list = await Post.findAll(condition);
|
||||
res.json(list);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user