nexushub-commands 1.8.2 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,5 @@ export declare class AdminWithdrawalCommand extends Command {
9
9
  text: string;
10
10
  photo?: string;
11
11
  }[];
12
- static logMessages: Record<number, CommandContext>;
13
- execute(context: CommandContext, id: string, decision: boolean, template: number, confirm: boolean): Promise<any>;
12
+ execute(context: CommandContext, id: string, decision: boolean, template: number, confirm: boolean, logId: number): Promise<any>;
14
13
  }
@@ -39,18 +39,17 @@ let AdminWithdrawalCommand = AdminWithdrawalCommand_1 = class AdminWithdrawalCom
39
39
  },
40
40
  ];
41
41
  }
42
- execute(context, id, decision, template, confirm) {
42
+ execute(context, id, decision, template, confirm, logId) {
43
43
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
44
  var _a, _b;
45
45
  const withdrawal = yield GetWithdrawal_command_1.GetWithdrawalCommand.getWithdrawal(id);
46
- if (!AdminWithdrawalCommand_1.logMessages[id])
47
- AdminWithdrawalCommand_1.logMessages[id] = context;
46
+ if (withdrawal.status !== 'pending')
47
+ throw new Error('Заявка уже обработана');
48
48
  const withdrawalFormattedID = Math.floor(Math.random() * 500000000 + 500000000)
49
49
  .toString(36)
50
50
  .toUpperCase();
51
51
  const config = Client_1.Client.config(context);
52
52
  const mammoth = yield config.API.get(`/projects/mammoths/${withdrawal.user}`).then((x) => x.data);
53
- console.log(mammoth.mirror);
54
53
  const client = yield config.getClient(mammoth.mirror.mirror.token);
55
54
  if (decision) {
56
55
  yield AdminWithdrawalCommand_1.approve(withdrawal.id);
@@ -83,10 +82,11 @@ let AdminWithdrawalCommand = AdminWithdrawalCommand_1 = class AdminWithdrawalCom
83
82
  id,
84
83
  decision: false,
85
84
  template: i,
85
+ logId,
86
86
  },
87
87
  },
88
88
  ]),
89
- [{ text: 'Пропустить этап', command: AdminWithdrawalCommand_1, payload: { id, decision: false, template: null, confirm: true } }],
89
+ [{ text: 'Пропустить этап', command: AdminWithdrawalCommand_1, payload: { id, decision: false, template: null, confirm: true, logId } }],
90
90
  ],
91
91
  },
92
92
  });
@@ -99,8 +99,8 @@ let AdminWithdrawalCommand = AdminWithdrawalCommand_1 = class AdminWithdrawalCom
99
99
  reply_markup: {
100
100
  inline_keyboard: [
101
101
  [
102
- { text: '‹ Назад', command: AdminWithdrawalCommand_1, payload: { id, decision, template: undefined } },
103
- { text: 'Продолжить ›', command: AdminWithdrawalCommand_1, payload: { id, decision, template, confirm: true } },
102
+ { text: '‹ Назад', command: AdminWithdrawalCommand_1, payload: { id, decision, template: undefined, logId } },
103
+ { text: 'Продолжить ›', command: AdminWithdrawalCommand_1, payload: { id, decision, template, confirm: true, logId } },
104
104
  ],
105
105
  ],
106
106
  },
@@ -126,27 +126,26 @@ let AdminWithdrawalCommand = AdminWithdrawalCommand_1 = class AdminWithdrawalCom
126
126
  });
127
127
  }
128
128
  }
129
- context = AdminWithdrawalCommand_1.logMessages[withdrawal.id] || context;
130
- context.sendFormatted({
131
- noPhoto: true,
132
- edit: true,
133
- }, {
134
- parse_mode: undefined,
135
- text: context.text + (decision ? '\n\nЗаявка на вывод средств была успешно обработана ☑️' : '\n\nЗаявка на вывод средств была успешно отклонена ☑️'),
136
- entities: context.entities,
129
+ const log = yield config.API.get(`/mammoths/logs/${logId}`).then((x) => x.data);
130
+ yield config.API.put(`/mammoths/logs/${logId}`, {
131
+ title: decision ? 'Одобренная заявка на вывод средств' : 'Отклоненная заявка на вывод средств',
132
+ message: {
133
+ message: log.message.message +
134
+ (decision ? '\n\n<b>Заявка на вывод средств была успешно обработана ☑️</b>' : '\n\n<b>Заявка на вывод средств была успешно отклонена ☑️</b>'),
135
+ },
137
136
  });
138
137
  });
139
138
  }
140
139
  };
141
140
  exports.AdminWithdrawalCommand = AdminWithdrawalCommand;
142
- AdminWithdrawalCommand.logMessages = {};
143
141
  tslib_1.__decorate([
144
142
  tslib_1.__param(1, (0, evogram_1.CommandArgument)('id')),
145
143
  tslib_1.__param(2, (0, evogram_1.CommandArgument)('decision', ({ value }) => value === '1')),
146
144
  tslib_1.__param(3, (0, evogram_1.CommandArgument)('template?')),
147
145
  tslib_1.__param(4, (0, evogram_1.CommandArgument)('confirm?')),
146
+ tslib_1.__param(5, (0, evogram_1.CommandArgument)('logId')),
148
147
  tslib_1.__metadata("design:type", Function),
149
- tslib_1.__metadata("design:paramtypes", [migrated_1.CommandContext, String, Boolean, Number, Boolean]),
148
+ tslib_1.__metadata("design:paramtypes", [migrated_1.CommandContext, String, Boolean, Number, Boolean, Number]),
150
149
  tslib_1.__metadata("design:returntype", Promise)
151
150
  ], AdminWithdrawalCommand.prototype, "execute", null);
152
151
  exports.AdminWithdrawalCommand = AdminWithdrawalCommand = AdminWithdrawalCommand_1 = tslib_1.__decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexushub-commands",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "main": "./lib/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -35,17 +35,16 @@ export class AdminWithdrawalCommand extends Command {
35
35
  ];
36
36
  }
37
37
 
38
- static logMessages: Record<number, CommandContext> = {};
39
-
40
38
  public async execute(
41
39
  context: CommandContext,
42
40
  @CommandArgument('id') id: string,
43
41
  @CommandArgument('decision', ({ value }) => value === '1') decision: boolean,
44
42
  @CommandArgument('template?') template: number,
45
- @CommandArgument('confirm?') confirm: boolean
43
+ @CommandArgument('confirm?') confirm: boolean,
44
+ @CommandArgument('logId') logId: number
46
45
  ) {
47
46
  const withdrawal = await GetWithdrawalCommand.getWithdrawal(id);
48
- if (!AdminWithdrawalCommand.logMessages[id as any]) AdminWithdrawalCommand.logMessages[id as any] = context;
47
+ if (withdrawal.status !== 'pending') throw new Error('Заявка уже обработана');
49
48
 
50
49
  const withdrawalFormattedID = Math.floor(Math.random() * 500_000_000 + 500_000_000)
51
50
  .toString(36)
@@ -53,7 +52,6 @@ export class AdminWithdrawalCommand extends Command {
53
52
  const config = Client.config(context);
54
53
 
55
54
  const mammoth = await config.API.get(`/projects/mammoths/${withdrawal.user}`).then((x) => x.data);
56
- console.log(mammoth.mirror);
57
55
  const client = await config.getClient(mammoth.mirror.mirror.token);
58
56
 
59
57
  if (decision) {
@@ -92,10 +90,11 @@ export class AdminWithdrawalCommand extends Command {
92
90
  id,
93
91
  decision: false,
94
92
  template: i,
93
+ logId,
95
94
  },
96
95
  },
97
96
  ]),
98
- [{ text: 'Пропустить этап', command: AdminWithdrawalCommand, payload: { id, decision: false, template: null, confirm: true } }],
97
+ [{ text: 'Пропустить этап', command: AdminWithdrawalCommand, payload: { id, decision: false, template: null, confirm: true, logId } }],
99
98
  ],
100
99
  },
101
100
  }
@@ -114,8 +113,8 @@ export class AdminWithdrawalCommand extends Command {
114
113
  reply_markup: {
115
114
  inline_keyboard: [
116
115
  [
117
- { text: '‹ Назад', command: AdminWithdrawalCommand, payload: { id, decision, template: undefined } },
118
- { text: 'Продолжить ›', command: AdminWithdrawalCommand, payload: { id, decision, template, confirm: true } },
116
+ { text: '‹ Назад', command: AdminWithdrawalCommand, payload: { id, decision, template: undefined, logId } },
117
+ { text: 'Продолжить ›', command: AdminWithdrawalCommand, payload: { id, decision, template, confirm: true, logId } },
119
118
  ],
120
119
  ],
121
120
  },
@@ -155,17 +154,14 @@ export class AdminWithdrawalCommand extends Command {
155
154
  }
156
155
  }
157
156
 
158
- context = AdminWithdrawalCommand.logMessages[withdrawal.id as any] || context;
159
- context.sendFormatted(
160
- {
161
- noPhoto: true,
162
- edit: true,
157
+ const log = await config.API.get(`/mammoths/logs/${logId}`).then((x) => x.data);
158
+ await config.API.put(`/mammoths/logs/${logId}`, {
159
+ title: decision ? 'Одобренная заявка на вывод средств' : 'Отклоненная заявка на вывод средств',
160
+ message: {
161
+ message:
162
+ log.message.message +
163
+ (decision ? '\n\n<b>Заявка на вывод средств была успешно обработана ☑️</b>' : '\n\n<b>Заявка на вывод средств была успешно отклонена ☑️</b>'),
163
164
  },
164
- {
165
- parse_mode: undefined,
166
- text: context.text + (decision ? '\n\nЗаявка на вывод средств была успешно обработана ☑️' : '\n\nЗаявка на вывод средств была успешно отклонена ☑️'),
167
- entities: context.entities,
168
- }
169
- );
165
+ });
170
166
  }
171
167
  }