Newer
Older
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
import { bot } from '../telegramBot';
import { PrismaClient } from '@prisma/client';
export const validateMessage = async (
response: any,
command: string,
alternateCommand: string,
chatId: number | string
) => {
const regExp = /[a-zA-Zа-яА-Я]/g;
const isValid = regExp.test(response);
if (isValid) {
await bot.sendMessage(chatId, command);
} else {
await bot.sendMessage(chatId, alternateCommand);
}
};
const prisma = new PrismaClient({});
export const createPrismaEntity = async (body: any) => {
switch (body.entity_type) {
case 'divider':
return prisma.divider.create({ data: { ...body } });
case 'paragraph':
return prisma.paragraph.create({ data: { ...body } });
case 'image':
return prisma.image.create({ data: { ...body } });
// case 'table':
// return prisma.table.create({ data: { ...body } });
}
};
export const getPrismaEntity = async (body: any) => {
switch (body.entity_type) {
case 'divider':
return prisma.divider.findFirst({
where: {
entity_uuid: body.entity_uuid
}
});
case 'paragraph':
return prisma.paragraph.findFirst({
where: {
entity_uuid: body.entity_uuid
}
});
case 'image':
return prisma.image.findFirst({
where: {
entity_uuid: body.entity_uuid
}
});
// case 'table':
// return prisma.table.findFirst({
// where: {
// entity_uuid: body.entity_uuid
// }
// });
}
};
export const updatePrismaEntity = async (body: any) => {
switch (body.entity_type) {
case 'divider':
return prisma.divider.update({
where: {
entity_uuid: body.entity_uuid
},
data: { ...body }
});
case 'paragraph':
return prisma.paragraph.update({
where: {
entity_uuid: body.entity_uuid
},
data: { ...body }
});
case 'image':
delete body.imageUrl;
return prisma.image.update({
where: {
entity_uuid: body.entity_uuid
},
data: { ...body }
});
// case 'table':
// return prisma.table.update({
// where: {
// entity_uuid: body.entity_uuid
// },
// data: { ...body }
// });
}
};
export const deletePrismaEntity = async (body: any) => {
switch (body.entity_type) {
case 'divider':
return prisma.divider.delete({
where: {
entity_uuid: body.entity_uuid
}
});
case 'paragraph':
return prisma.paragraph.delete({
where: {
entity_uuid: body.entity_uuid
}
});
case 'image':
return prisma.image.delete({
where: {
entity_uuid: body.entity_uuid
}
});
// case 'table':
// return prisma.table.delete({
// where: {
// entity_uuid: body.entity_uuid
// }
// }
// });
}
};