Skip to content

Commit c070978

Browse files
committed
searches midi by tag or name
1 parent a85025e commit c070978

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/midi.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { createDB } from "./supabase";
44
import { MidiDevice } from "./types/midiDevice";
55

66
export const midisHandler = async (req: Request, res: Response) => {
7-
const { tag, page, deviceId } = req.query;
7+
const { page, deviceId, search } = req.query;
88
const limit = 12;
99
const supabase = await createDB();
1010

1111
const query = supabase.from("midi").select("*, midi_devices(*)");
1212

13+
/**
14+
* search for MIDI by device id
15+
*/
1316
if (deviceId) {
1417
console.log("setting device id: ", deviceId);
1518
query.eq("midi_devices.device", deviceId);
@@ -31,8 +34,18 @@ export const midisHandler = async (req: Request, res: Response) => {
3134
query.in("id", midiIds);
3235
}
3336

34-
if (tag) {
35-
query.contains("tags", [tag.toString().toUpperCase()]);
37+
/**
38+
* Search for MIDI by search term
39+
*/
40+
if (search) {
41+
/**
42+
* Searching for name or tag
43+
*/
44+
query.or(
45+
`tags.cs.{${search
46+
.toString()
47+
.toUpperCase()}}, metadata->>name.ilike.*${search.toString()}*`
48+
);
3649
}
3750

3851
const startRange = (page ? +page : 0) * limit;

0 commit comments

Comments
 (0)