-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d73b22
commit daf6790
Showing
19 changed files
with
191 additions
and
134 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
code/server/src/ts/controllers/http/workspace/documentHandlers.ts
This file was deleted.
Oops, something went wrong.
52 changes: 41 additions & 11 deletions
52
code/server/src/ts/controllers/http/workspace/resourcesHandlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
code/server/src/ts/controllers/ws/namespaces/document/operation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
code/server/src/ts/controllers/ws/namespaces/document/title.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DocumentDatabase, NoteSpaceDatabase, ResourceDatabase, WorkspaceDatabase } from '@database/types'; | ||
import { ResourcesDB } from '@database/pg/resourcesDB'; | ||
import { WorkspaceDB } from '@database/pg/workspaceDB'; | ||
|
||
export class NoteSpaceDB implements NoteSpaceDatabase{ | ||
readonly document: DocumentDatabase; | ||
readonly resource: ResourceDatabase; | ||
readonly workspace: WorkspaceDatabase; | ||
|
||
constructor(document: DocumentDatabase) { | ||
this.document = document; | ||
this.resource = new ResourcesDB(); | ||
this.workspace = new WorkspaceDB(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,44 @@ | ||
export class ResourcesDB { | ||
import sql from '@database/pg/sql'; | ||
import { ResourceInputModel, WorkspaceResource } from '@notespace/shared/workspace/types/resource'; | ||
import { ResourceDatabase } from '@database/types'; | ||
|
||
async createResource(resource) { | ||
return await this.database.createResource(resource); | ||
export class ResourcesDB implements ResourceDatabase{ | ||
|
||
|
||
async createResource(resource : ResourceInputModel) : Promise<string> { | ||
const results = await sql` | ||
INSERT INTO resource ${sql(resource)} | ||
RETURNING id | ||
`; | ||
if (results.length === 0) throw new Error('Resource not created'); | ||
return results[0].id; | ||
} | ||
async getResource(id) { | ||
return await this.database.getResource(id); | ||
|
||
async getResource(id : string) : Promise<WorkspaceResource> { | ||
const results : WorkspaceResource[] = await sql` | ||
SELECT * FROM resource WHERE id = ${id} | ||
`; | ||
if (results.length === 0) throw new Error('Resource not found'); | ||
if (results.length > 1) throw new Error('Multiple resources found'); | ||
return results[0]; | ||
} | ||
async updateResource(resource) { | ||
await this.database.updateResource(resource); | ||
|
||
async updateResource(resource : Partial<WorkspaceResource>) : Promise<void> { | ||
if (!resource.id) throw new Error('Resource id not provided'); | ||
|
||
const results = await sql` | ||
UPDATE resource | ||
SET ${sql(resource)} | ||
WHERE id = ${resource.id} | ||
`; | ||
if (results.length === 0) throw new Error('Resource not updated'); | ||
} | ||
async deleteResource(id) { | ||
await this.database.deleteResource(id); | ||
|
||
async deleteResource(id : string) { | ||
const results = await sql` | ||
DELETE FROM resource | ||
WHERE id = ${id} | ||
`; | ||
if (results.length === 0) throw new Error('Resource not deleted'); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.