@@ -4,17 +4,6 @@ import { blockService } from '@/services';
4
4
import { StatusCode , transactionHandler } from '@/aops' ;
5
5
import { BlockDoc } from '@/models' ;
6
6
7
- export const create = transactionHandler (
8
- async ( req : Request , res : Response ) : Promise < void > => {
9
- const { parent, block } = await blockService . create ( {
10
- parentId : req . params . parentId ,
11
- index : req . body . index ,
12
- blockDTO : req . body . block ,
13
- } ) ;
14
- res . status ( StatusCode . CREATED ) . json ( { parent, block } ) ;
15
- } ,
16
- ) ;
17
-
18
7
export const readAll = async ( req : Request , res : Response ) : Promise < void > => {
19
8
const blocks = await blockService . readAll ( req . params . pageId ) ;
20
9
const blockMap = blocks . reduce (
@@ -28,49 +17,19 @@ export const readAll = async (req: Request, res: Response): Promise<void> => {
28
17
res . status ( StatusCode . OK ) . json ( { blockMap } ) ;
29
18
} ;
30
19
31
- export const update = async ( req : Request , res : Response ) : Promise < void > => {
32
- const block = await blockService . update ( req . params . blockId , req . body . block ) ;
33
- res . status ( StatusCode . OK ) . json ( { block } ) ;
20
+ export const publish = async ( req : Request , res : Response ) => {
21
+ const blocks = await blockService . readAll ( ( req . session as any ) . pageId ) ;
22
+ const blockMap = blocks . reduce (
23
+ ( map : { [ blockId : string ] : BlockDoc } , block ) => {
24
+ map [ block . id ] = block ;
25
+ return map ;
26
+ } ,
27
+ { } ,
28
+ ) ;
29
+ req . app
30
+ . get ( 'io' )
31
+ . of ( '/page' )
32
+ . to ( ( req . session as any ) . pageId )
33
+ . emit ( 'PageUpdate' , blockMap ) ;
34
+ res . status ( StatusCode . OK ) . json ( res . locals . result ) ;
34
35
} ;
35
-
36
- export const move = transactionHandler (
37
- async ( req : Request , res : Response ) : Promise < void > => {
38
- const { block, from, to } = await blockService . move (
39
- req . params . blockId ,
40
- req . params . toId ,
41
- req . body . index ,
42
- ) ;
43
- res . status ( StatusCode . OK ) . json ( { block, from, to } ) ;
44
- } ,
45
- ) ;
46
-
47
- export const deleteCascade = transactionHandler (
48
- async ( req : Request , res : Response ) : Promise < void > => {
49
- const parent = await blockService . deleteCascade ( req . params . blockId ) ;
50
- res . status ( StatusCode . OK ) . json ( { parent } ) ;
51
- } ,
52
- ) ;
53
-
54
- export const createAndUpdate = transactionHandler (
55
- async ( req : Request , res : Response ) : Promise < void > => {
56
- const { create, update } = req . body ;
57
- const { parent, block } = await blockService . create ( create ) ;
58
- let updated : BlockDoc = null ;
59
- if ( update ) {
60
- updated = await blockService . update ( update . blockId , update ) ;
61
- }
62
- res . status ( StatusCode . OK ) . json ( { parent, block, updated } ) ;
63
- } ,
64
- ) ;
65
-
66
- export const deleteAndUpdate = transactionHandler (
67
- async ( req : Request , res : Response ) : Promise < void > => {
68
- const { deleteId, update } = req . body ;
69
- const parent = await blockService . deleteOnly ( deleteId ) ;
70
- let updated : BlockDoc = null ;
71
- if ( update ) {
72
- updated = await blockService . update ( update . blockId , update ) ;
73
- }
74
- res . status ( StatusCode . OK ) . json ( { parent, updated } ) ;
75
- } ,
76
- ) ;
0 commit comments