mirror of
https://github.com/directus/directus.git
synced 2026-01-25 21:18:31 -05:00
Add /users/me/track/page endpoint
This commit is contained in:
@@ -64,11 +64,6 @@ router.patch(
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO implement skip-activity query param so we don't end up saving activity / revisions
|
||||
* for every single page navigation that was done
|
||||
*/
|
||||
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const primaryKey = await service.update(req.body, req.accountability.user);
|
||||
const item = await service.readByKey(primaryKey, req.sanitizedQuery);
|
||||
@@ -77,6 +72,25 @@ router.patch(
|
||||
})
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/me/track/page',
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
if (!req.body.last_page) {
|
||||
throw new InvalidPayloadException(`"last_page" key is required.`);
|
||||
}
|
||||
|
||||
const service = new UsersService();
|
||||
await service.update({ last_page: req.body.last_page }, req.accountability.user);
|
||||
|
||||
return res.status(200).end();
|
||||
})
|
||||
);
|
||||
|
||||
router.patch(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
|
||||
@@ -82,7 +82,9 @@ export default class ItemsService implements AbstractService {
|
||||
// string / uuid primary
|
||||
let primaryKey = payloadWithoutAlias[primaryKeyField];
|
||||
|
||||
const result = await trx.insert(payloadWithoutAlias).into(this.collection);
|
||||
const result = await trx
|
||||
.insert(payloadWithoutAlias, primaryKeyField)
|
||||
.into(this.collection);
|
||||
|
||||
// Auto-incremented id
|
||||
if (!primaryKey) primaryKey = result[0];
|
||||
@@ -110,7 +112,7 @@ export default class ItemsService implements AbstractService {
|
||||
const activityPrimaryKeys: PrimaryKey[] = [];
|
||||
|
||||
for (const activityRecord of activityRecords) {
|
||||
const result = await trx.insert(activityRecord).into('directus_activity');
|
||||
const result = await trx.insert(activityRecord, 'id').into('directus_activity');
|
||||
activityPrimaryKeys.push(result[0]);
|
||||
}
|
||||
|
||||
@@ -246,7 +248,9 @@ export default class ItemsService implements AbstractService {
|
||||
const activityPrimaryKeys: PrimaryKey[] = [];
|
||||
|
||||
for (const activityRecord of activityRecords) {
|
||||
const result = await trx.insert(activityRecord).into('directus_activity');
|
||||
const result = await trx
|
||||
.insert(activityRecord, 'id')
|
||||
.into('directus_activity');
|
||||
activityPrimaryKeys.push(result[0]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user