Skip to content

Commit

Permalink
fix very strange casting issue
Browse files Browse the repository at this point in the history
I forgot to add the single object type and for some reason it didn't error and instead had silently cast the result?
  • Loading branch information
3vorp committed Oct 23, 2024
1 parent 3ca20b8 commit abd38ae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/multer": "^1.4.12",
"@types/node": "^22.7.8",
"@types/node": "^22.7.9",
"@types/response-time": "^2.3.8",
"@types/statuses": "^2.0.5",
"@types/swagger-ui-express": "^4.1.6",
Expand Down
11 changes: 7 additions & 4 deletions src/v2/controller/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,21 @@ export class PostController extends Controller {
/**
* Updates the post to the given ID
* @param id Post ID
* @param postToCreate Post information
* @param postToUpdate Post information
*/
@Response<BadRequestError>(400)
@Response<PermissionError>(403)
@Security("discord", ["administrator"])
@Put("{id}")
public updatePost(
@Path() id: number,
@Body() postToCreate: CreateWebsitePost,
@Body() postToUpdate: CreateWebsitePost,
): Promise<WebsitePost> {
postToCreate.description = this.sanitizeDescription(postToCreate.description);
return this.service.update(id, postToCreate);
postToUpdate.description = this.sanitizeDescription(postToUpdate.description);

console.log(JSON.stringify(postToUpdate.changelog, null, 4));

return this.service.update(id, postToUpdate);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface PostDownload {

export interface PostChangelog {
// recursive type (arbitrary nesting possible as long as it terminates with strings somewhere)
[category: string]: (string | PostChangelog)[];
[category: string]: PostChangelog | (string | PostChangelog)[];
}

export interface CreateWebsitePost {
Expand Down
21 changes: 10 additions & 11 deletions src/v2/repository/posts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ export default class PostFirestormRepository implements WebsitePostRepository {
return posts.get(id);
}

getByPermalink(permalink: string): Promise<WebsitePost> {
return posts
.search([
{
criteria: "==",
field: "permalink",
value: permalink,
},
])
.then((results) => results[0]);
async getByPermalink(permalink: string): Promise<WebsitePost> {
const results = await posts.search([
{
criteria: "==",
field: "permalink",
value: permalink,
},
]);
return results[0];
}

create(postToCreate: CreateWebsitePost): Promise<WebsitePost> {
Expand All @@ -41,8 +40,8 @@ export default class PostFirestormRepository implements WebsitePostRepository {
update(id: number, post: CreateWebsitePost): Promise<WebsitePost> {
const postWithId = {
...post,
[ID_FIELD]: String(id),
};
postWithId[ID_FIELD] = String(id);
return posts.set(id, postWithId).then(() => posts.get(id));
}

Expand Down

0 comments on commit abd38ae

Please sign in to comment.