api/frontend/src/services/reactions.ts
kolaente a5c51d4b1e feat: emoji reactions for tasks and comments (#2196)
This PR adds reactions for tasks and comments, similar to what you can do on Gitea, GitHub, Slack and plenty of other tools.

Reviewed-on: vikunja/vikunja#2196
Co-authored-by: kolaente <k@knt.li>
Co-committed-by: kolaente <k@knt.li>
2024-03-12 19:25:58 +00:00

33 lines
925 B
TypeScript

import AbstractService from '@/services/abstractService'
import type {IAbstract} from '@/modelTypes/IAbstract'
import ReactionModel from '@/models/reaction'
import type {IReactionPerEntity} from '@/modelTypes/IReaction'
import UserModel from '@/models/user'
export default class ReactionService extends AbstractService {
constructor() {
super({
getAll: '{kind}/{id}/reactions',
create: '{kind}/{id}/reactions',
delete: '{kind}/{id}/reactions/delete',
})
}
modelFactory(data: Partial<IAbstract>): ReactionModel {
return new ReactionModel(data)
}
modelGetAllFactory(data: Partial<IReactionPerEntity>): Partial<IReactionPerEntity> {
Object.keys(data).forEach(reaction => {
data[reaction] = data[reaction]?.map(u => new UserModel(u))
})
return data
}
async delete(model: IAbstract) {
const finalUrl = this.getReplacedRoute(this.paths.delete, model)
return super.post(finalUrl, model)
}
}