feat: add tagging alerts and sorting on tags
This commit is contained in:
@@ -115,7 +115,7 @@ export async function ctaskRoutes(fastify: FastifyInstance) {
|
||||
const { field } = req.params as { field: string };
|
||||
|
||||
try {
|
||||
const uniqueValues = await getUniqueFields(field, "task", req.user);
|
||||
const uniqueValues = await getUniqueFields(field, "ctasks", req.user);
|
||||
return res.code(200).send(uniqueValues);
|
||||
} catch (err) {
|
||||
return err;
|
||||
|
||||
@@ -28,6 +28,7 @@ const taskSchema = new mongoose.Schema({
|
||||
type: mongoose.Types.ObjectId,
|
||||
ref: "user",
|
||||
},
|
||||
taggedUsers: Array,
|
||||
});
|
||||
|
||||
export const taskFields = Object.keys(taskSchema.paths).filter(
|
||||
|
||||
@@ -37,6 +37,7 @@ export async function createTask(
|
||||
content: input.note,
|
||||
},
|
||||
task.pid,
|
||||
"ctasks",
|
||||
user
|
||||
);
|
||||
}
|
||||
@@ -80,6 +81,25 @@ export async function listTasks(
|
||||
const sortObj = getSortObject(params, taskFields);
|
||||
const filterObj = getFilterObject(params) || [];
|
||||
|
||||
let taggedFilter = [];
|
||||
if (sortObj.taggedUsers) {
|
||||
taggedFilter = [
|
||||
{
|
||||
$addFields: {
|
||||
taggedUsers: {
|
||||
$filter: {
|
||||
input: "$taggedUsers",
|
||||
as: "user",
|
||||
cond: { $eq: ["$$user.userId", user.userId] },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{ $match: { "taggedUsers.0": { $exists: true } } },
|
||||
{ $sort: { "taggedUsers.taggedAt": sortObj.taggedUsers } },
|
||||
];
|
||||
}
|
||||
|
||||
const taskList = await taskModel.aggregate([
|
||||
{
|
||||
$match: {
|
||||
@@ -90,6 +110,7 @@ export async function listTasks(
|
||||
],
|
||||
},
|
||||
},
|
||||
...taggedFilter,
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
|
||||
Reference in New Issue
Block a user