Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add final config backend #16

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dialog-challenge-back/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion dialog-challenge-back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node dist/server.js"
"start": "npx tsc && node dist/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-express": "^3.12.0",
"express": "^4.18.2",
"graphql": "^16.7.1",
"string-similarity": "^4.0.4",
"typescript": "^5.1.3"
},
"devDependencies": {
"@types/string-similarity": "^4.0.0"
}
}
17 changes: 15 additions & 2 deletions dialog-challenge-back/resolvers/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import db from "../db.json";
import { findBestMatch } from "string-similarity";

export const resolvers = {
Query: {
list: (_: any, args: { name?: string }) => {
const { name } = args;
if (name) {
const regex = new RegExp(name, "i");
return db.filter((user) => regex.test(user.name));
const term = name.trim().replace(/\s/g, "\\s.*");
const regex = new RegExp(term, "i");

const matches = findBestMatch(
term,
db.map((user) => user.name)
);
const similarNames = matches.ratings
.filter((rating) => rating.rating >= 0.5)
.map((rating) => rating.target);

return db.filter(
(user) => regex.test(user.name) || similarNames.includes(user.name)
);
}
return db;
},
Expand Down
2 changes: 1 addition & 1 deletion dialog-challenge-back/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolvers } from "./resolvers/resolvers";
import { loggingMiddleware } from "./middlewares/loggingMiddleware";

const startServer = async () => {
const server = new ApolloServer({ typeDefs, resolvers });
const server = new ApolloServer({ typeDefs, resolvers, debug: true });

const app = express();

Expand Down
3 changes: 2 additions & 1 deletion dialog-challenge-back/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"sourceMap": true
}
}