Spaces:
Running
Running
File size: 8,862 Bytes
9f29339 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | "use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkspaceController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const workspace_service_1 = require("./workspace.service");
const better_auth_guard_1 = require("../auth/better-auth.guard");
const subscription_guard_1 = require("../billing/subscription.guard");
const workspace_dto_1 = require("./workspace.dto");
let WorkspaceController = class WorkspaceController {
workspaceService;
constructor(workspaceService) {
this.workspaceService = workspaceService;
}
async findAll(req) {
const userId = req.userId;
return this.workspaceService.findByUser(userId);
}
async create(req, data) {
const userId = req.userId;
return this.workspaceService.create(userId, data);
}
async findOne(req, id) {
const userId = req.userId;
return this.workspaceService.findById(id, userId);
}
async update(req, id, data) {
const userId = req.userId;
return this.workspaceService.update(id, userId, data);
}
async delete(req, id) {
const userId = req.userId;
await this.workspaceService.delete(id, userId);
}
async inviteMember(req, workspaceId, data) {
const userId = req.userId;
return this.workspaceService.inviteMember(workspaceId, userId, data.email, data.role);
}
async removeMember(req, workspaceId, memberId) {
const userId = req.userId;
await this.workspaceService.removeMember(workspaceId, userId, memberId);
}
async updateMemberRole(req, workspaceId, memberId, data) {
const userId = req.userId;
return this.workspaceService.updateMemberRole(workspaceId, userId, memberId, data.role);
}
};
exports.WorkspaceController = WorkspaceController;
__decorate([
(0, common_1.Get)(),
(0, swagger_1.ApiOperation)({
summary: "List user workspaces",
description: "Get all workspaces where the current user is a member",
}),
(0, swagger_1.ApiResponse)({
status: 200,
description: "List of workspaces retrieved successfully",
}),
__param(0, (0, common_1.Req)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "findAll", null);
__decorate([
(0, common_1.Post)(),
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
(0, swagger_1.ApiOperation)({
summary: "Create workspace",
description: "Create a new workspace with the current user as owner",
}),
(0, swagger_1.ApiResponse)({
status: 201,
description: "Workspace created successfully",
}),
(0, swagger_1.ApiResponse)({ status: 409, description: "Slug already exists" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, workspace_dto_1.CreateWorkspaceDto]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "create", null);
__decorate([
(0, common_1.Get)(":id"),
(0, swagger_1.ApiOperation)({ summary: "Get workspace details" }),
(0, swagger_1.ApiParam)({ name: "id", description: "Workspace ID" }),
(0, swagger_1.ApiResponse)({ status: 200, description: "Workspace details retrieved" }),
(0, swagger_1.ApiResponse)({ status: 404, description: "Workspace not found" }),
(0, swagger_1.ApiResponse)({ status: 403, description: "Access denied" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Param)("id")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "findOne", null);
__decorate([
(0, common_1.Put)(":id"),
(0, swagger_1.ApiOperation)({ summary: "Update workspace" }),
(0, swagger_1.ApiParam)({ name: "id", description: "Workspace ID" }),
(0, swagger_1.ApiResponse)({ status: 200, description: "Workspace updated" }),
(0, swagger_1.ApiResponse)({ status: 403, description: "Insufficient permissions" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Param)("id")),
__param(2, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String, workspace_dto_1.UpdateWorkspaceDto]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "update", null);
__decorate([
(0, common_1.Delete)(":id"),
(0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
(0, swagger_1.ApiOperation)({
summary: "Delete workspace",
description: "Only workspace owner can delete",
}),
(0, swagger_1.ApiParam)({ name: "id", description: "Workspace ID" }),
(0, swagger_1.ApiResponse)({ status: 204, description: "Workspace deleted" }),
(0, swagger_1.ApiResponse)({ status: 403, description: "Only owner can delete" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Param)("id")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "delete", null);
__decorate([
(0, common_1.Post)(":id/members"),
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
(0, swagger_1.ApiOperation)({
summary: "Invite member",
description: "Invite a user to join the workspace",
}),
(0, swagger_1.ApiParam)({ name: "id", description: "Workspace ID" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Param)("id")),
__param(2, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String, workspace_dto_1.InviteMemberDto]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "inviteMember", null);
__decorate([
(0, common_1.Delete)(":id/members/:memberId"),
(0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
(0, swagger_1.ApiOperation)({ summary: "Remove member from workspace" }),
(0, swagger_1.ApiParam)({ name: "id", description: "Workspace ID" }),
(0, swagger_1.ApiParam)({ name: "memberId", description: "User ID of member to remove" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Param)("id")),
__param(2, (0, common_1.Param)("memberId")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String, String]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "removeMember", null);
__decorate([
(0, common_1.Put)(":id/members/:memberId/role"),
(0, swagger_1.ApiOperation)({
summary: "Update member role",
description: "Only workspace owner can change roles",
}),
(0, swagger_1.ApiParam)({ name: "id", description: "Workspace ID" }),
(0, swagger_1.ApiParam)({ name: "memberId", description: "User ID of member" }),
__param(0, (0, common_1.Req)()),
__param(1, (0, common_1.Param)("id")),
__param(2, (0, common_1.Param)("memberId")),
__param(3, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, String, String, workspace_dto_1.UpdateMemberRoleDto]),
__metadata("design:returntype", Promise)
], WorkspaceController.prototype, "updateMemberRole", null);
exports.WorkspaceController = WorkspaceController = __decorate([
(0, swagger_1.ApiTags)("Workspaces"),
(0, swagger_1.ApiBearerAuth)("jwt"),
(0, common_1.UseGuards)(better_auth_guard_1.BetterAuthGuard, subscription_guard_1.SubscriptionGuard),
(0, common_1.Controller)("workspaces"),
__metadata("design:paramtypes", [workspace_service_1.WorkspaceService])
], WorkspaceController);
//# sourceMappingURL=workspace.controller.js.map |