-
Notifications
You must be signed in to change notification settings - Fork 18
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
convert to typescript #95
Conversation
config/db.server.config.ts
Outdated
* @param databaseName the name of the database being connected to | ||
* @param isTestDatabase conditional for if the database in use is for testing | ||
*/ | ||
export function connect(databaseName: string, isTestDatabase: boolean = false): Promise<typeof database> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like these function parameters are never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I overwrote some of the code so that it runs locally. Will change this before opening
config/db.server.config.ts
Outdated
if (isTestDatabase) { | ||
return database.connection.readyState; | ||
} else { | ||
return database.connection.readyState; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if statement is redundant if we do the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'm not sure what the thought was there 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine though the tests fail all fail on me. but i probably haven't set something up properly. i'll report back.
well done on keeping the conversion unopinionated!
"@types/convict": "^6.1.1", | ||
"@types/express": "^4.17.13", | ||
"@types/mocha": "^9.1.0", | ||
"@types/mongoose": "^5.11.97", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongoose has it's own types afaik, so don't need this?
dbServerRoutes(app); | ||
forumServerRoutes(app); | ||
userServerRoutes(app); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is dbServerRoutes
etc usually put into a reexports file so that you can do the imports on a single line? eg: as a file routes/routes.module.ts
lib/middleware.lib.ts
Outdated
User.searchUserByAuthToken(authToken, function (result) { | ||
if (result.status !== 200) { | ||
return res.sendStatus(result.status).message(result.message); | ||
console.log(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra log here. noting just in case you missed; probably on purpose because authtoken stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this was in there before. I will remove it
export function isValidDocumentID(id) { | ||
const regExpDocumentID = new RegExp('^[a-fA-F0-9]{24}$'); | ||
return id && typeof id === 'string' && id.length === 24 && regExpDocumentID.test(id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goodness... we can probably kill some of this validate stuff w/ types when we refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely
}) | ||
.catch((err) => { | ||
// Forum post is already in the database with unique attributes, return duplicate conflict error | ||
if (err.code === 11000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code seems like magic to me; what is this error code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a mongodb error code. I think we should fix this in another ticket later
* @param params object containing forum post attributes | ||
* @param done function callback, returns status code, and message if error, or JSON if successful | ||
*/ | ||
export function insertPost (params, done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should run prettier over the project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add this as part of #93
models/user.server.model.ts
Outdated
}); | ||
.then((res) => { | ||
if (res.hashedPassword.match(hashPassword(plaintextPassword))) { | ||
return done({status: 200, res}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should replace these magics with the enums if avail.
server.ts
Outdated
|
||
// Database name - use environment variable DATABASE_NAME or enter here | ||
const databaseName = process.env.DATABASE_NAME; | ||
const databaseName = process.env.DATABASE_NAME as string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem to be used & don't envvars always cast as string? (is the explicit cast required?)
the tests are very very broken it's not just you |
updates['comments'] = updates.comments ? result.comments.concat(updates.comments) : result.comments | ||
|
||
// If the update does not just involve up votes, down votes, or comments, and actual edits | ||
if (Object.keys(updates).length > 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this magic number a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not focus on all the unrelated issues right now, there are more than enough of them to fix later. If we try fix them now we cant parallelise efficiently
*/ | ||
describe("Database connection test", function() { | ||
it("should connect to and disconnect from the database with correct statuses", async function() { | ||
const testDatabaseName = process.env.DATABASE_TEST_NAME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable looks like it is never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah as per our meeting we will be ignoring tests until they can be reviewed and fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they're very broken and dependant on a prod database. I have started some initial work on fixing them but we want to get this in first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yikes. thats good and makes sense though. thanks for the heads up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
Converts the backend codebase to typescript
Fixes/resolves #90
Type of change
Checklist:
Leave blank if not applicable
I have completed these steps when making this pull request:
Before opening the PR for review: