MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / addPrizeToWarehouse

Function addPrizeToWarehouse

lottery/lottery.ts:172–204  ·  view source on GitHub ↗
(warehouseName: string, prizeText: string, stock: number)

Source from the content-addressed store, hash-verified

170 WHERE warehouse_name = ? AND prize_text = ?
171 `).get(warehouseName, prizeText) as any;
172
173 if (existingPrize) {
174 // Update existing prize stock
175 const updateStmt = db.prepare(`
176 UPDATE prize_warehouse
177 SET stock_count = stock_count + ?
178 WHERE id = ?
179 `);
180 updateStmt.run(stock, existingPrize.id);
181 } else {
182 // Get next order index for new prize
183 const maxOrderStmt = db.prepare(`
184 SELECT COALESCE(MAX(order_index), 0) + 1 as next_order
185 FROM prize_warehouse WHERE warehouse_name = ?
186 `);
187 const nextOrder = (maxOrderStmt.get(warehouseName) as any)?.next_order || 1;
188
189 // Insert new prize
190 const stmt = db.prepare(`
191 INSERT INTO prize_warehouse (warehouse_name, prize_text, stock_count, order_index, created_at)
192 VALUES (?, ?, ?, ?, ?)
193 `);
194 stmt.run(warehouseName, prizeText, stock, nextOrder, Date.now());
195 }
196}
197
198function getPrizeWarehouses(): string[] {
199 if (!db) return [];
200
201 const stmt = db.prepare(`
202 SELECT DISTINCT warehouse_name FROM prize_warehouse
203 ORDER BY warehouse_name
204 `);
205 return stmt.all().map((row: any) => row.warehouse_name);
206}
207

Callers 1

lotteryFunction · 0.85

Calls 2

runMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected