Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {repository} from '@loopback/repository';
import {get, getModelSchemaRef, param, post, requestBody} from '@loopback/rest';
import {TodoListImage} from '../models';
import {TodoListRepository} from '../repositories';
export class TodoListImageController {
constructor(
@repository(TodoListRepository) protected todoListRepo: TodoListRepository,
) {}
@post('/todo-lists/{id}/image', {
responses: {
'200': {
description: 'create todoListImage model instance',
content: {
'application/json': {schema: getModelSchemaRef(TodoListImage)},
},
},
},
})
async create(
@param.path.number('id') id: number,
@requestBody() image: TodoListImage,
): Promise {
return this.todoListRepo.image(id).create(image);
}
@get('/todo-lists/{id}/image', {
responses: {
'200': {
description: 'The image belonging to the TodoList',
content: {
}),
},
},
})
todo: Omit,
): Promise {
return this.todoListRepo.todos(id).create(todo);
}
@get('/todo-lists/{id}/todos', {
responses: {
'200': {
description: "Array of Todo's belonging to TodoList",
content: {
'application/json': {
schema: {type: 'array', items: getModelSchemaRef(Todo)},
},
},
},
},
})
async find(
@param.path.number('id') id: number,
@param.query.object('filter') filter?: Filter,
): Promise {
return this.todoListRepo.todos(id).find(filter);
}
@patch('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo PATCH success count',
if (!this.endpoints) this.endpoints = {};
}
}
export class ModelAdminController {
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE)
private app: TodoListApplication,
) {}
@post('/discover', {
responses: {
200: {
description: 'Information about discovered models',
content: {
'application/json': {schema: getModelSchemaRef(DiscoverResponse)},
},
},
},
})
async discoverAndPublishModels(
@requestBody() {connectionString, tableNames}: DiscoverRequest,
): Promise {
const result = new DiscoverResponse();
const ds = await getDataSourceForConnectionString(
this.app,
connectionString,
);
for (const table of tableNames) {
const basePath = await this.discoverAndPublish(ds, table);
export function model(
statusCode: number,
description: string,
modelCtor: Function & {prototype: T},
options?: JsonSchemaOptions,
) {
return response(statusCode, description, {
schema: getModelSchemaRef(modelCtor, options),
});
}
export function array(
statusCode: number,
description: string,
modelCtor: Function & {prototype: T},
options?: JsonSchemaOptions,
) {
return response(statusCode, description, {
schema: {
type: 'array',
items: getModelSchemaRef(modelCtor, options),
},
});
}
}
requestBody,
} from '@loopback/rest';
import {Note} from '../models';
import {NoteRepository} from '../repositories';
export class NoteController {
constructor(
@repository(NoteRepository)
public noteRepository: NoteRepository,
) {}
@post('/notes', {
responses: {
'200': {
description: 'Note model instance',
content: {'application/json': {schema: getModelSchemaRef(Note)}},
},
},
})
async create(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Note, {title: 'NewNote', exclude: ['id']}),
},
},
})
note: Omit,
): Promise {
return this.noteRepository.create(note);
}
post,
requestBody,
} from '@loopback/rest';
import {Todo} from '../models';
import {TodoListRepository} from '../repositories';
export class TodoListTodoController {
constructor(
@repository(TodoListRepository) protected todoListRepo: TodoListRepository,
) {}
@post('/todo-lists/{id}/todos', {
responses: {
'200': {
description: 'TodoList.Todo model instance',
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
async create(
@param.path.number('id') id: number,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {
title: 'NewTodoInTodoList',
exclude: ['id'],
optional: ['todoListId'],
}),
},
},
})
async count(
@param.query.object('where', getWhereSchemaFor(TodoList))
where?: Where,
): Promise {
return this.todoListRepository.count(where);
}
@get('/todo-lists', {
responses: {
'200': {
description: 'Array of TodoList model instances',
content: {
'application/json': {
schema: {
type: 'array',
items: getModelSchemaRef(TodoList, {includeRelations: true}),
},
},
},
},
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(TodoList))
filter?: Filter,
): Promise {
return this.todoListRepository.find(filter);
}
@patch('/todo-lists', {
responses: {
'200': {
function body(
modelCtor: Function & {prototype: T},
options?: JsonSchemaOptions,
) {
return requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(modelCtor, options),
},
},
});
}
patch,
post,
put,
requestBody,
} from '@loopback/rest';
import {Todo, TodoList} from '../models';
import {TodoRepository} from '../repositories';
export class TodoController {
constructor(@repository(TodoRepository) protected todoRepo: TodoRepository) {}
@post('/todos', {
responses: {
'200': {
description: 'Todo model instance',
content: {'application/json': {schema: getModelSchemaRef(Todo)}},
},
},
})
async createTodo(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
todo: Omit,
): Promise {
return this.todoRepo.create(todo);
}