Skip to content

Commit

Permalink
Merge pull request #869 from NoodleOfDeath/dev
Browse files Browse the repository at this point in the history
fix interactions ~api
  • Loading branch information
NoodleOfDeath authored Jan 29, 2024
2 parents d3f0ee8 + 685b2d1 commit 55bbca7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/server/src/api/v1/controllers/category/CategoryController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ export class CategoryController extends BaseController {
): Promise<PublicCategoryAttributes> {
const user = req.jwt?.user;
const category = await Category.findOne({ where: { name: target } });
if (!user || !category) {
return undefined;
}
if (body.revert) {
await CategoryInteraction.destroy({
where: {
targetId: category.id,
type,
userId: user.id,
}
});
}
const interaction = await CategoryInteraction.create({
...body,
remoteAddr: req.ip,
targetId: category?.id,
targetId: category.id,
type,
userId: user?.id,
userId: user.id,
});
if (!interaction) {
throw new InternalError('Failed to create interaction');
Expand Down
16 changes: 14 additions & 2 deletions src/server/src/api/v1/controllers/publisher/PublisherController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ export class PublisherController extends BaseController {
): Promise<PublicPublisherAttributes> {
const user = req.jwt?.user;
const publisher = await Publisher.findOne({ where: { name: target } });
if (!user || !publisher) {
return undefined;
}
if (body.revert) {
await PublisherInteraction.destroy({
where: {
targetId: publisher.id,
type,
userId: user.id,
}
});
}
const interaction = await PublisherInteraction.create({
...body,
remoteAddr: req.ip,
targetId: publisher?.id,
targetId: publisher.id,
type,
userId: user?.id,
userId: user.id,
});
if (!interaction) {
throw new InternalError('Failed to create interaction');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ export class SummaryController extends BaseControllerWithPersistentStorageAccess
@Body() body: Partial<InteractionCreationAttributes>
): Promise<PublicSummaryAttributes> {
const user = req.jwt?.user;
if (body.revert && user) {
await SummaryInteraction.destroy({
where: {
targetId,
type,
userId: user.id,
}
});
}
const interaction = await SummaryInteraction.create({
...body,
remoteAddr: req.ip,
Expand Down

0 comments on commit 55bbca7

Please sign in to comment.