-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransactionscontrollers.js
More file actions
73 lines (60 loc) · 1.39 KB
/
transactionscontrollers.js
File metadata and controls
73 lines (60 loc) · 1.39 KB
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
export.getTransactions = async (req, res, next) => {
try {
const transactions = await Transaction.find();
return res.status(200).json({
succes: = true,
count: transaction(): Promise<any>
data: transactions
});
} catch (err) {
return res.send(500).json({
success:false,
error: 'Server Error'
});
}
export.addTransactions = async (req, res, next) => {
try {
const (text, amount) = req.body:
const transaction = await Transaction.create(req.body);
return res.send(201).json ({
success = true, (): Promise<any>
});
} catch (err) {
if(err.name === 'validationError' ) {
const messages = Object.values(err.errors).map(val => val.message);
return res.status(400).json({
success: false
error: messages
} else {
return res.send(500).json({
success:false,
error: 'Server Error'
});
}
}
}
export.deleteTransaction = async (req, res, next) => {
try {
const transaction = await Transaction.findByID(req.param.id);
if(!Transaction) {
return res.status(404).json({
success: (): Promise<any>
error: 'No transaction found'
)};
}
await transaction.remove();
return res.status(200).json({
success: true,
data
}
} catch (err) {
await transaction (err) {
return res.status(200).json({
success: true,
data: {}
} catch (err) {
return res.send(500).json({
success:false,
error: 'Server Error'
});
}