Skip to content

Commit

Permalink
fix update route
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Jun 13, 2023
1 parent 3e0521a commit a128635
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/plugins/data/server/search/routes/response_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,20 @@ export const searchSessionsFindSchema = schema.object({
saved_objects: schema.arrayOf(searchSessionSchema),
statuses: schema.recordOf(schema.string(), searchSessionStatusSchema),
});

const referencesSchema = schema.arrayOf(
schema.object({ id: schema.string(), type: schema.string(), name: schema.string() })
);

export const searchSessionsUpdateSchema = schema.object({
id: schema.string(),
type: schema.string(),
updated_at: schema.maybe(schema.string()),
version: schema.maybe(schema.string()),
namespaces: schema.maybe(schema.arrayOf(schema.string())),
references: schema.maybe(referencesSchema),
attributes: schema.object({
name: schema.maybe(schema.string()),
expires: schema.maybe(schema.string()),
}),
});
13 changes: 13 additions & 0 deletions src/plugins/data/server/search/routes/response_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ export interface SearchSessionsFindRestResponse {
*/
statuses: Record<string, SearchSessionStatusRestResponse>;
}

export interface SearchSessionsUpdateRestResponse {
id: string;
type: string;
updated_at?: string;
version?: string;
namespaces?: string[];
references?: Array<{ id: string; type: string; name: string }>;
attributes: {
name?: string;
expires?: string;
};
}
16 changes: 11 additions & 5 deletions src/plugins/data/server/search/routes/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
SearchSessionRestResponse,
SearchSessionStatusRestResponse,
SearchSessionsFindRestResponse,
SearchSessionsUpdateRestResponse,
} from './response_types';
import {
searchSessionSchema,
searchSessionStatusSchema,
searchSessionsFindSchema,
searchSessionsUpdateSchema,
} from './response_schema';

const STORE_SEARCH_SESSIONS_ROLE_TAG = `access:store_search_session`;
Expand Down Expand Up @@ -262,17 +264,22 @@ export function registerSessionRoutes(router: DataPluginRouter, logger: Logger):
expires: schema.maybe(schema.string()),
}),
},
response: {
200: {
body: searchSessionsUpdateSchema,
},
},
},
},
async (context, request, res) => {
console.log('put /{id}');
const { id } = request.params;
const { name, expires } = request.body;
try {
const searchContext = await context.search;
// todo
const response = await searchContext.updateSession(id, { name, expires });

const response: SearchSessionsUpdateRestResponse = await searchContext.updateSession(id, {
name,
expires,
});
return res.ok({
body: response,
});
Expand All @@ -298,7 +305,6 @@ export function registerSessionRoutes(router: DataPluginRouter, logger: Logger):
},
},
async (context, request, res) => {
console.log('post /{id}/_extend');
const { id } = request.params;
const { expires } = request.body;
try {
Expand Down

0 comments on commit a128635

Please sign in to comment.