@raclettejs/core 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/CONTRIBUTING.md +23 -0
- package/bin/cli.js +1 -1
- package/dev/README.md +4 -0
- package/dist/cli.js +135 -124
- package/dist/cli.js.map +4 -4
- package/dist/index.js +9 -8
- package/dist/index.js.map +4 -4
- package/package.json +12 -6
- package/raclette.default.config.yaml +60 -0
- package/services/backend/delay-api-debugger.sh +0 -0
- package/services/backend/package.json +1 -0
- package/services/backend/src/app.ts +4 -0
- package/services/backend/src/core/config/configService.ts +10 -1
- package/services/backend/src/core/events/eventEmitter.ts +32 -7
- package/services/backend/src/core/http/request-params.plugin.ts +2 -2
- package/services/backend/src/core/pluginSystem/pluginFastifyInstance.ts +4 -1
- package/services/backend/src/core/pluginSystem/pluginTypes.ts +3 -1
- package/services/backend/src/core/sockets/createSystemEventHandlers.ts +7 -0
- package/services/backend/src/core/sockets/index.ts +61 -13
- package/services/backend/src/core/sockets/socketManager.ts +452 -105
- package/services/backend/src/core/sockets/socketTypes.ts +13 -1
- package/services/backend/src/core/sockets/workSessionJoinPayload.ts +106 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.get.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.getAll.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.hardDelete.ts +16 -19
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.patch.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.post.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.remove.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/composition.service.ts +2 -3
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.get.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.getAll.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.hardDelete.ts +16 -19
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.patch.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.post.bulk.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.post.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.remove.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.restore.ts +12 -15
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/interactionLink.service.ts +2 -3
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.get.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.getAll.ts +4 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.hardDelete.ts +12 -17
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.patch.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.post.bulk.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.post.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.remove.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.restore.ts +12 -15
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/project.service.ts +1 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.get.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.getAll.ts +4 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.hardDelete.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.patch.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.post.ts +4 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.remove.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.get.ts +1 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.getAll.ts +1 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.hardDelete.ts +10 -15
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.patch.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.post.bulk.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.post.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.remove.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.restore.ts +12 -15
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/tag.service.ts +1 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.get.ts +1 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.getAll.ts +1 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.hardDelete.ts +10 -15
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.patch.ts +4 -6
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.patchLastProject.ts +4 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.post.ts +3 -1
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.remove.ts +3 -4
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.restore.ts +12 -15
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/events/index.ts +45 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/helpers/crud.ts +12 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/helpers/payload.ts +21 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/index.ts +55 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/index.ts +19 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.get.ts +53 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.getAll.ts +39 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.hardDelete.ts +53 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.patch.ts +58 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.post.ts +53 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.remove.ts +52 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/workSession.model.ts +65 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/workSession.schema.ts +125 -0
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/workSession.service.ts +351 -0
- package/services/backend/src/corePlugins/raclette__core/backend/index.ts +2 -0
- package/services/backend/src/corePlugins/raclette__core/frontend/generated-config.ts +159 -24
- package/services/backend/src/modules/authentication/index.ts +255 -4
- package/services/backend/src/modules/hooks/rate-limiter.ts +21 -0
- package/services/backend/src/types/custom-fastify.d.ts +17 -0
- package/services/backend/src/utils/request.utils.ts +4 -1
- package/services/backend/types/index.d.ts +15 -1
- package/services/backend/yarn.lock +13 -4
- package/services/frontend/index.html +1 -1
- package/services/frontend/provision/entrypoint.sh +0 -0
- package/services/frontend/src/core/lib/configService.ts +1 -1
- package/services/frontend/src/core/lib/dataHelper.ts +1 -1
- package/services/frontend/src/core/lib/eggs/snow.ts +49 -20
- package/services/frontend/src/core/lib/helpers/index.ts +1 -0
- package/services/frontend/src/core/lib/helpers/removeEmpty.ts +69 -0
- package/services/frontend/src/core/lib/httpClient.ts +19 -0
- package/services/frontend/src/core/main.ts +20 -10
- package/services/frontend/src/core/setup/socket.ts +4 -3
- package/services/frontend/src/core/setup/socketClient.ts +31 -3
- package/services/frontend/src/core/setup/socketEvents.ts +92 -8
- package/services/frontend/src/core/store/index.ts +5 -1
- package/services/frontend/src/core/store/reducers/compositions/index.ts +2 -2
- package/services/frontend/src/core/store/reducers/interactionLinks/index.ts +1 -1
- package/services/frontend/src/core/store/reducers/widgets/reducers.ts +1 -2
- package/services/frontend/src/core/store/types/index.ts +0 -1
- package/services/frontend/src/core/types/PluginRegistrar.ts +8 -6
- package/services/frontend/src/core/types/Store.ts +1 -0
- package/services/frontend/src/orchestrator/components/composition/WidgetsLayoutLoader.vue +68 -8
- package/services/frontend/src/orchestrator/components/menu/UserMenu.vue +17 -5
- package/services/frontend/src/orchestrator/components/welcomeScreen/AdminWelcomeScreen.vue +1 -1
- package/services/frontend/src/orchestrator/composables/index.ts +1 -0
- package/services/frontend/src/orchestrator/composables/usePluginApi.ts +0 -3
- package/services/frontend/src/orchestrator/composables/useRouteState.ts +23 -4
- package/services/frontend/src/orchestrator/composables/useWidgetLifecycle.ts +166 -0
- package/services/frontend/src/orchestrator/helpers/index.ts +1 -0
- package/services/frontend/src/orchestrator/i18n/de-DE.json +1 -1
- package/services/frontend/src/orchestrator/i18n/en-EU.json +1 -1
- package/services/frontend/src/orchestrator/i18n/sk.json +1 -1
- package/services/frontend/src/orchestrator/index.ts +34 -4
- package/services/frontend/src/orchestrator/router/routeParserHelper.ts +106 -1
- package/services/frontend/src/orchestrator/types/Widgets.ts +2 -0
- package/services/frontend/types.ts +1 -0
- package/src/README.md +404 -0
- package/src/types.ts +19 -5
- package/templates/README.md +0 -0
- package/types/index.ts +18 -4
- package/services/backend/.gitignore +0 -17
- package/services/frontend/.gitignore +0 -35
- package/yarn.lock +0 -2937
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WorkSession } from "../workSession.schema"
|
|
2
|
+
import type { FrontendPayloadRequestData, PluginFastifyInstance } from "types"
|
|
3
|
+
|
|
4
|
+
export const registerPayload = (fastify: PluginFastifyInstance) => {
|
|
5
|
+
fastify.registerPayloadHandler<WorkSession>("workSession", {
|
|
6
|
+
type: "workSession",
|
|
7
|
+
displayName: (workSession: WorkSession) => workSession._id || "",
|
|
8
|
+
completion: (workSession: WorkSession) => workSession._id || "",
|
|
9
|
+
fields: () => ({
|
|
10
|
+
owner: "NONE",
|
|
11
|
+
}),
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const createWorkSessionPayload = async (
|
|
16
|
+
fastify: PluginFastifyInstance,
|
|
17
|
+
items: WorkSession[],
|
|
18
|
+
requestData: FrontendPayloadRequestData,
|
|
19
|
+
) => {
|
|
20
|
+
return await fastify.createPayload("workSession", items, requestData)
|
|
21
|
+
}
|
package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { PluginFastifyInstance } from "types"
|
|
2
|
+
import registerRoutes from "./routes"
|
|
3
|
+
import { createModels } from "./workSession.model"
|
|
4
|
+
import { createWorkSessionService } from "./workSession.service"
|
|
5
|
+
import { registerPayload } from "./helpers/payload"
|
|
6
|
+
import { registerCrud } from "./helpers/crud"
|
|
7
|
+
import { registerSchemas } from "./workSession.schema"
|
|
8
|
+
|
|
9
|
+
const registerWorkSession = async (fastify: PluginFastifyInstance) => {
|
|
10
|
+
/*
|
|
11
|
+
* ---------------------------------------------------------------------
|
|
12
|
+
* CREATE AND REGISTER ALL YOUR MODELS
|
|
13
|
+
* ---------------------------------------------------------------------
|
|
14
|
+
*/
|
|
15
|
+
const workSessionModel = createModels(fastify)
|
|
16
|
+
|
|
17
|
+
// create and pass in the model to your service
|
|
18
|
+
const workSessionService = createWorkSessionService(workSessionModel)
|
|
19
|
+
|
|
20
|
+
// decorate the service to the instance, so we can easily call it everywhere
|
|
21
|
+
fastify.custom.workSessionService = workSessionService
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* ---------------------------------------------------------------------
|
|
25
|
+
* REGISTER ALL YOUR ROUTES
|
|
26
|
+
* ---------------------------------------------------------------------
|
|
27
|
+
*/
|
|
28
|
+
try {
|
|
29
|
+
await fastify.register((instance) => registerRoutes(instance))
|
|
30
|
+
} catch (error) {
|
|
31
|
+
fastify.log.error(`Failed to register routes.`, error)
|
|
32
|
+
throw error // Let the application handle the error
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
registerPayload(fastify)
|
|
36
|
+
registerCrud(fastify)
|
|
37
|
+
registerSchemas(fastify)
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
workSession: {
|
|
41
|
+
operations: {
|
|
42
|
+
read: workSessionService._readWorkSession.bind(workSessionService),
|
|
43
|
+
readAll: workSessionService._readWorkSessions.bind(workSessionService),
|
|
44
|
+
create: workSessionService._createWorkSession.bind(workSessionService),
|
|
45
|
+
update: workSessionService._updateWorkSession.bind(workSessionService),
|
|
46
|
+
},
|
|
47
|
+
keywords: ["workSession", "session"],
|
|
48
|
+
metadata: {
|
|
49
|
+
description: "A work session for user interactions.",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default registerWorkSession
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PluginFastifyInstance } from "types"
|
|
2
|
+
import get from "./route.workSession.get"
|
|
3
|
+
import getAll from "./route.workSession.getAll"
|
|
4
|
+
import patch from "./route.workSession.patch"
|
|
5
|
+
import post from "./route.workSession.post"
|
|
6
|
+
import hardDelete from "./route.workSession.hardDelete"
|
|
7
|
+
import remove from "./route.workSession.remove"
|
|
8
|
+
|
|
9
|
+
const registerRoutes = async (fastify: PluginFastifyInstance) => {
|
|
10
|
+
await fastify.get("/workSession/all", getAll(fastify))
|
|
11
|
+
await fastify.get("/workSession/:_id", get(fastify))
|
|
12
|
+
|
|
13
|
+
await fastify.post("/workSession", post(fastify))
|
|
14
|
+
await fastify.patch("/workSession/:_id", patch(fastify))
|
|
15
|
+
await fastify.delete("/workSession/:_id", remove(fastify))
|
|
16
|
+
await fastify.delete("/workSession/:_id/hard", hardDelete(fastify))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default registerRoutes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Static } from "@sinclair/typebox"
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from "fastify"
|
|
3
|
+
import { PluginFastifyInstance } from "types"
|
|
4
|
+
import { Type } from "@sinclair/typebox"
|
|
5
|
+
|
|
6
|
+
const ParamsSchema = Type.Object({
|
|
7
|
+
_id: Type.String(),
|
|
8
|
+
})
|
|
9
|
+
type Params = Static<typeof ParamsSchema>
|
|
10
|
+
|
|
11
|
+
export default (fastify: PluginFastifyInstance) => {
|
|
12
|
+
const workSessionService = fastify.custom.workSessionService
|
|
13
|
+
|
|
14
|
+
const handler = async (
|
|
15
|
+
req: FastifyRequest<{
|
|
16
|
+
Params: Params
|
|
17
|
+
}>,
|
|
18
|
+
reply: FastifyReply,
|
|
19
|
+
) => {
|
|
20
|
+
try {
|
|
21
|
+
const { _id } = req.params
|
|
22
|
+
|
|
23
|
+
const payload = await workSessionService.readWorkSession(
|
|
24
|
+
fastify,
|
|
25
|
+
req.requestParams,
|
|
26
|
+
_id,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if (!payload) {
|
|
30
|
+
return reply.notFound("WorkSession not found")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return payload
|
|
34
|
+
} catch (error: any) {
|
|
35
|
+
fastify.log.error(error.message)
|
|
36
|
+
return reply.internalServerError(error.message)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
handler,
|
|
42
|
+
onRequest: [fastify.authenticate],
|
|
43
|
+
config: {
|
|
44
|
+
type: "dataRead",
|
|
45
|
+
},
|
|
46
|
+
schema: {
|
|
47
|
+
summary: "Get a workSession by id",
|
|
48
|
+
tags: ["core/workSession"],
|
|
49
|
+
|
|
50
|
+
params: ParamsSchema,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify"
|
|
2
|
+
import type { PluginFastifyInstance } from "types"
|
|
3
|
+
|
|
4
|
+
const permissions = ["user.isAdmin"]
|
|
5
|
+
|
|
6
|
+
export default (fastify: PluginFastifyInstance) => {
|
|
7
|
+
const workSessionService = fastify.custom.workSessionService
|
|
8
|
+
|
|
9
|
+
const handler = async (req: FastifyRequest<{}>, reply: FastifyReply) => {
|
|
10
|
+
try {
|
|
11
|
+
const payload = await workSessionService.readWorkSessions(
|
|
12
|
+
fastify,
|
|
13
|
+
req.requestParams,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if (!payload) {
|
|
17
|
+
return reply.code(204)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return payload
|
|
21
|
+
} catch (error: any) {
|
|
22
|
+
fastify.log.error(error.message)
|
|
23
|
+
return reply.internalServerError(error.message)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
handler,
|
|
29
|
+
onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
|
|
30
|
+
config: {
|
|
31
|
+
type: "dataRead",
|
|
32
|
+
},
|
|
33
|
+
schema: {
|
|
34
|
+
summary: "Get all workSessions",
|
|
35
|
+
tags: ["core/workSession"],
|
|
36
|
+
params: {},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Static } from "@sinclair/typebox"
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from "fastify"
|
|
3
|
+
import { PluginFastifyInstance } from "types"
|
|
4
|
+
import { Type } from "@sinclair/typebox"
|
|
5
|
+
|
|
6
|
+
const permissions = ["user.isAdmin"]
|
|
7
|
+
|
|
8
|
+
const ParamsSchema = Type.Object({
|
|
9
|
+
_id: Type.String(),
|
|
10
|
+
})
|
|
11
|
+
type Params = Static<typeof ParamsSchema>
|
|
12
|
+
|
|
13
|
+
export default (fastify: PluginFastifyInstance) => {
|
|
14
|
+
const workSessionService = fastify.custom.workSessionService
|
|
15
|
+
|
|
16
|
+
const handler = async (
|
|
17
|
+
req: FastifyRequest<{
|
|
18
|
+
Params: Params
|
|
19
|
+
}>,
|
|
20
|
+
reply: FastifyReply,
|
|
21
|
+
) => {
|
|
22
|
+
try {
|
|
23
|
+
const { _id } = req.params
|
|
24
|
+
|
|
25
|
+
const payload = await workSessionService.hardDeleteWorkSession(
|
|
26
|
+
fastify,
|
|
27
|
+
req.requestParams,
|
|
28
|
+
_id,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
return payload
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
fastify.log.error(error.message)
|
|
34
|
+
return reply.internalServerError(error.message)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
handler,
|
|
40
|
+
onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
|
|
41
|
+
config: {
|
|
42
|
+
type: "dataHardDeleted",
|
|
43
|
+
broadcastChannels: ["workSessionHardDeleted"],
|
|
44
|
+
},
|
|
45
|
+
schema: {
|
|
46
|
+
summary: "Hard delete a workSession by id",
|
|
47
|
+
description: "Permanently removes a workSession",
|
|
48
|
+
tags: ["core/workSession"],
|
|
49
|
+
|
|
50
|
+
params: ParamsSchema,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { WorkSessionBody } from "../workSession.service"
|
|
2
|
+
import type { Static } from "@sinclair/typebox"
|
|
3
|
+
import type { FastifyReply, FastifyRequest } from "fastify"
|
|
4
|
+
import { PluginFastifyInstance } from "types"
|
|
5
|
+
import { Type } from "@sinclair/typebox"
|
|
6
|
+
import { workSessionUpdateSchema } from "../workSession.schema"
|
|
7
|
+
|
|
8
|
+
const permissions = ["user.isAdmin"]
|
|
9
|
+
|
|
10
|
+
const ParamsSchema = Type.Object({
|
|
11
|
+
_id: Type.String(),
|
|
12
|
+
})
|
|
13
|
+
type Params = Static<typeof ParamsSchema>
|
|
14
|
+
|
|
15
|
+
export default (fastify: PluginFastifyInstance) => {
|
|
16
|
+
const workSessionService = fastify.custom.workSessionService
|
|
17
|
+
|
|
18
|
+
const handler = async (
|
|
19
|
+
req: FastifyRequest<{
|
|
20
|
+
Params: Params
|
|
21
|
+
Body: WorkSessionBody
|
|
22
|
+
}>,
|
|
23
|
+
reply: FastifyReply,
|
|
24
|
+
) => {
|
|
25
|
+
try {
|
|
26
|
+
const { _id } = req.params
|
|
27
|
+
|
|
28
|
+
const payload = await workSessionService.updateWorkSession(
|
|
29
|
+
fastify,
|
|
30
|
+
req.requestParams,
|
|
31
|
+
_id,
|
|
32
|
+
req.body,
|
|
33
|
+
req.user._id,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return payload
|
|
37
|
+
} catch (error: any) {
|
|
38
|
+
fastify.log.error(error.message)
|
|
39
|
+
return reply.internalServerError(error.message)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
handler,
|
|
45
|
+
onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
|
|
46
|
+
config: {
|
|
47
|
+
type: "dataUpdate",
|
|
48
|
+
broadcastChannels: ["workSessionUpdated"],
|
|
49
|
+
},
|
|
50
|
+
schema: {
|
|
51
|
+
summary: "Update a workSession",
|
|
52
|
+
tags: ["core/workSession"],
|
|
53
|
+
|
|
54
|
+
params: ParamsSchema,
|
|
55
|
+
body: workSessionUpdateSchema,
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify"
|
|
2
|
+
import { PluginFastifyInstance } from "types"
|
|
3
|
+
import {
|
|
4
|
+
workSessionCreateSchema,
|
|
5
|
+
type WorkSessionCreate,
|
|
6
|
+
} from "../workSession.schema"
|
|
7
|
+
|
|
8
|
+
const permissions = ["user.isAdmin"]
|
|
9
|
+
|
|
10
|
+
export default (fastify: PluginFastifyInstance) => {
|
|
11
|
+
const workSessionService = fastify.custom.workSessionService
|
|
12
|
+
|
|
13
|
+
const handler = async (
|
|
14
|
+
req: FastifyRequest<{
|
|
15
|
+
Body: WorkSessionCreate
|
|
16
|
+
}>,
|
|
17
|
+
reply: FastifyReply,
|
|
18
|
+
) => {
|
|
19
|
+
try {
|
|
20
|
+
// Set userId from authenticated user if not provided
|
|
21
|
+
const workSessionBody = {
|
|
22
|
+
...req.body,
|
|
23
|
+
userId: req.body.userId || req.user?._id,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const payload = await workSessionService.createWorkSession(
|
|
27
|
+
fastify,
|
|
28
|
+
req.requestParams,
|
|
29
|
+
workSessionBody,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return payload
|
|
33
|
+
} catch (error: any) {
|
|
34
|
+
fastify.log.error(error.message)
|
|
35
|
+
return reply.internalServerError(error.message)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
handler,
|
|
41
|
+
onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
|
|
42
|
+
config: {
|
|
43
|
+
type: "dataCreate",
|
|
44
|
+
broadcastChannels: ["workSessionCreated"],
|
|
45
|
+
},
|
|
46
|
+
schema: {
|
|
47
|
+
summary: "Create a new workSession",
|
|
48
|
+
tags: ["core/workSession"],
|
|
49
|
+
|
|
50
|
+
body: workSessionCreateSchema,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Static } from "@sinclair/typebox"
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from "fastify"
|
|
3
|
+
import type { PluginFastifyInstance } from "types"
|
|
4
|
+
import { Type } from "@sinclair/typebox"
|
|
5
|
+
|
|
6
|
+
const permissions = ["user.isAdmin"]
|
|
7
|
+
|
|
8
|
+
const ParamsSchema = Type.Object({
|
|
9
|
+
_id: Type.String(),
|
|
10
|
+
})
|
|
11
|
+
type Params = Static<typeof ParamsSchema>
|
|
12
|
+
|
|
13
|
+
export default (fastify: PluginFastifyInstance) => {
|
|
14
|
+
const workSessionService = fastify.custom.workSessionService
|
|
15
|
+
|
|
16
|
+
const handler = async (
|
|
17
|
+
req: FastifyRequest<{
|
|
18
|
+
Params: Params
|
|
19
|
+
}>,
|
|
20
|
+
reply: FastifyReply,
|
|
21
|
+
) => {
|
|
22
|
+
try {
|
|
23
|
+
const { _id } = req.params
|
|
24
|
+
|
|
25
|
+
const payload = await workSessionService.removeWorkSession(
|
|
26
|
+
fastify,
|
|
27
|
+
req.requestParams,
|
|
28
|
+
_id,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
return payload
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
fastify.log.error(error.message)
|
|
34
|
+
return reply.internalServerError(error.message)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
handler,
|
|
40
|
+
onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
|
|
41
|
+
config: {
|
|
42
|
+
type: "dataUpdate",
|
|
43
|
+
broadcastChannels: ["workSessionDeleted"],
|
|
44
|
+
},
|
|
45
|
+
schema: {
|
|
46
|
+
summary: "Soft delete a workSession by id",
|
|
47
|
+
tags: ["core/workSession"],
|
|
48
|
+
|
|
49
|
+
params: ParamsSchema,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { PluginFastifyInstance } from "types"
|
|
2
|
+
import mongoose from "mongoose"
|
|
3
|
+
const { Schema } = mongoose
|
|
4
|
+
|
|
5
|
+
export const MODEL_BASENAME = "workSession"
|
|
6
|
+
|
|
7
|
+
const workSessionSchema = new Schema(
|
|
8
|
+
{
|
|
9
|
+
_id: {
|
|
10
|
+
type: String,
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
userId: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
accessType: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
default: "anonymous",
|
|
22
|
+
enum: ["anonymous"],
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
compositionId: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
project: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: false,
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
expiryDate: {
|
|
36
|
+
type: Date,
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
isActive: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: true,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
permissions: {
|
|
46
|
+
type: Number,
|
|
47
|
+
default: 6, // read+write
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
pluginData: {
|
|
51
|
+
type: Schema.Types.Mixed,
|
|
52
|
+
default: {},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
composition: {
|
|
56
|
+
type: Schema.Types.Mixed,
|
|
57
|
+
required: false,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{ timestamps: true },
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
export const createModels = (fastify: PluginFastifyInstance) => {
|
|
64
|
+
return fastify.createModel(MODEL_BASENAME, workSessionSchema)
|
|
65
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Static } from "@sinclair/typebox"
|
|
2
|
+
import type { Document } from "mongoose"
|
|
3
|
+
import { Type } from "@sinclair/typebox"
|
|
4
|
+
import type { PluginFastifyInstance } from "types"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Base WorkSession Schema - Fields common to all operations
|
|
8
|
+
*/
|
|
9
|
+
const baseWorkSessionSchema = {
|
|
10
|
+
userId: Type.Optional(Type.String()),
|
|
11
|
+
accessType: Type.Optional(
|
|
12
|
+
Type.String({ default: "anonymous", enum: ["anonymous"] }),
|
|
13
|
+
),
|
|
14
|
+
compositionId: Type.Optional(Type.String()),
|
|
15
|
+
project: Type.String(), // Project ID for payload wrapper (temporary solution)
|
|
16
|
+
expiryDate: Type.Optional(Type.String({ format: "date-time" })),
|
|
17
|
+
isActive: Type.Optional(Type.Boolean({ default: true })),
|
|
18
|
+
permissions: Type.Optional(Type.Number({ default: 6 })),
|
|
19
|
+
pluginData: Type.Optional(
|
|
20
|
+
Type.Record(Type.String(), Type.Any(), { default: {} }),
|
|
21
|
+
),
|
|
22
|
+
composition: Type.Optional(Type.Any()),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Full WorkSession Schema - Used for response serialization and database model
|
|
27
|
+
*/
|
|
28
|
+
export const workSessionSchema = Type.Object(
|
|
29
|
+
{
|
|
30
|
+
_id: Type.String(),
|
|
31
|
+
...baseWorkSessionSchema,
|
|
32
|
+
createdAt: Type.String({ format: "date-time" }),
|
|
33
|
+
updatedAt: Type.String({ format: "date-time" }),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
$id: "#workSession/base",
|
|
37
|
+
title: "core/workSession",
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* WorkSession Create Schema - For POST operations
|
|
43
|
+
*/
|
|
44
|
+
export const workSessionCreateSchema = Type.Object(
|
|
45
|
+
{
|
|
46
|
+
_id: Type.Optional(Type.String()),
|
|
47
|
+
...baseWorkSessionSchema,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
$id: "#workSession/create",
|
|
51
|
+
title: "core/workSession-create",
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* WorkSession Update Schema - For PATCH operations
|
|
57
|
+
*/
|
|
58
|
+
export const workSessionUpdateSchema = Type.Object(
|
|
59
|
+
{
|
|
60
|
+
_id: Type.Optional(Type.String()),
|
|
61
|
+
...baseWorkSessionSchema,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
$id: "#workSession/update",
|
|
65
|
+
title: "core/workSession-update",
|
|
66
|
+
},
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Type Utilities
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
type DateTimeFields = {
|
|
74
|
+
createdAt: Date
|
|
75
|
+
updatedAt: Date
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type RawWorkSession = Static<typeof workSessionSchema>
|
|
79
|
+
export type WorkSession = Omit<RawWorkSession, keyof DateTimeFields> &
|
|
80
|
+
DateTimeFields
|
|
81
|
+
|
|
82
|
+
type RawWorkSessionCreate = Static<typeof workSessionCreateSchema>
|
|
83
|
+
export type WorkSessionCreate = RawWorkSessionCreate
|
|
84
|
+
|
|
85
|
+
type RawWorkSessionUpdate = Static<typeof workSessionUpdateSchema>
|
|
86
|
+
export type WorkSessionUpdate = RawWorkSessionUpdate
|
|
87
|
+
|
|
88
|
+
export interface WorkSessionDoc extends Document, WorkSession {
|
|
89
|
+
_id: string
|
|
90
|
+
}
|
|
91
|
+
export type AnyWorkSession = WorkSession | WorkSessionDoc
|
|
92
|
+
|
|
93
|
+
/** Shape of work session attached to req by authenticatedOrWorksession */
|
|
94
|
+
export interface RequestWorkSession {
|
|
95
|
+
_id: string
|
|
96
|
+
userId: string
|
|
97
|
+
accessType: string
|
|
98
|
+
compositionId: string
|
|
99
|
+
project?: string
|
|
100
|
+
expiryDate: Date
|
|
101
|
+
isActive: boolean
|
|
102
|
+
permissions?: number
|
|
103
|
+
pluginData?: Record<string, unknown>
|
|
104
|
+
composition?: unknown
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Register Schema/Type Generation for Shared Folder
|
|
109
|
+
*/
|
|
110
|
+
export const registerSchemas = (fastify: PluginFastifyInstance) => {
|
|
111
|
+
fastify.registerSchema({
|
|
112
|
+
schema: workSessionSchema,
|
|
113
|
+
name: "WorkSession",
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
fastify.registerSchema({
|
|
117
|
+
schema: workSessionCreateSchema,
|
|
118
|
+
name: "WorkSessionCreate",
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
fastify.registerSchema({
|
|
122
|
+
schema: workSessionUpdateSchema,
|
|
123
|
+
name: "WorkSessionUpdate",
|
|
124
|
+
})
|
|
125
|
+
}
|