Docs/Controllers
Full Controller Example
TypeScript
import { get, post, patch, del, defineRequest, defineResponse, withAuth } from 'alado';
import { bearerAuth } from './auth/bearer.auth';
import { CredentialsDto, UserDto, Id } from './dto';
export class UserController {
@get('/users', { tags: ['User'] })
@defineResponse({
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: [],
})
async list(req) {
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: [],
};
}
@post('/user', { tags: ['User'] })
@defineResponse({
statusCode: 201,
headers: { 'Content-Type': 'application/json' },
body: {},
})
@defineRequest({ body: CredentialsDto })
async create(req) {
return {
statusCode: 201,
headers: { 'Content-Type': 'application/json' },
body: req.body,
};
}
@patch('/user/:id', { tags: ['User'] })
@withAuth(bearerAuth)
@defineResponse({
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: {},
})
@defineRequest({
path: Id,
body: UserDto,
})
async update(req) {
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: req.body,
};
}
@del('/user/:id', { tags: ['User'] })
@withAuth(bearerAuth)
@defineRequest({ path: Id })
async remove(req) {
return {
statusCode: 204,
headers: {},
body: null,
};
}
}