Skip to content

Commit

Permalink
Merge pull request #320 from dfpc-coe/filter
Browse files Browse the repository at this point in the history
Filter Layers
  • Loading branch information
ingalls authored Sep 4, 2024
2 parents f006c2a + 8980e4a commit e75174e
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 93 deletions.
19 changes: 19 additions & 0 deletions api/lib/models/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ export default class LayerModel extends Modeler<typeof Layer> {
super(pool, Layer);
}

async tasks(): Promise<string[]> {
const pgres = await this.pool
.select({
task: Layer.task
})
.from(Layer)

if (pgres.length === 0) {
return []
} else {
const taskSet: Set<string> = new Set();
for (const t of pgres) {
taskSet.add(t.task.replace(/-v\d+\.\d+\.\d+/, ''))
}

return Array.from(taskSet);
}
}

async augmented_list(query: GenericListInput = {}): Promise<GenericList<Static<typeof AugmentedLayer>>> {
const order = query.order && query.order === 'desc' ? desc : asc;
const orderBy = order(query.sort ? this.key(query.sort) : this.requiredPrimaryKey());
Expand Down
4 changes: 4 additions & 0 deletions api/routes/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ export default async function router(schema: Schema, config: Config) {
order: Default.Order,
sort: Type.Optional(Type.String({default: 'created', enum: Object.keys(Layer)})),
filter: Default.Filter,
task: Type.Optional(Type.String()),
data: Type.Optional(Type.Integer({ minimum: 1 })),
connection: Type.Optional(Type.Integer({ minimum: 1 })),
}),
res: Type.Object({
total: Type.Integer(),
tasks: Type.Array(Type.String()),
status: Type.Object({
healthy: Type.Integer(),
alarm: Type.Integer(),
Expand All @@ -50,6 +52,7 @@ export default async function router(schema: Schema, config: Config) {
name ~* ${req.query.filter}
AND (${Param(req.query.connection)}::BIGINT IS NULL OR ${Param(req.query.connection)}::BIGINT = layers.connection)
AND (${Param(req.query.data)}::BIGINT IS NULL OR ${Param(req.query.data)}::BIGINT = layers.data)
AND (${Param(req.query.task)}::TEXT IS NULL OR Starts_With(layers.task, ${Param(req.query.task)}::TEXT))
`
});

Expand All @@ -65,6 +68,7 @@ export default async function router(schema: Schema, config: Config) {
res.json({
status,
total: list.total,
tasks: await config.models.Layer.tasks(),
items: list.items.map((layer) => {
return {
status: alarms.get(layer.id) || 'unknown',
Expand Down
Loading

0 comments on commit e75174e

Please sign in to comment.