本文整理汇总了TypeScript中hapi.IReply.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IReply.default方法的具体用法?TypeScript IReply.default怎么用?TypeScript IReply.default使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.IReply
的用法示例。
在下文中一共展示了IReply.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handler
export default async function handler(req: Request, reply: IReply) {
const { hackId: hackid } = req.params
const hack = await HackModel
.findOne({ hackid }, 'hackid challenges')
.populate('challenges', 'challengeid name')
.exec()
if (hack === null) {
reply(Boom.notFound('Hack not found'))
return
}
const challenges = hack.challenges.map((challenge): JSONApi.ResourceIdentifierObject => ({
type: 'challenges',
id: challenge.challengeid,
}))
const includedChallenges = hack.challenges.map((challenge): ChallengeResource.ResourceObject => ({
links: { self: `/challenges/${challenge.challengeid}` },
type: 'challenges',
id: challenge.challengeid,
attributes: { name: challenge.name },
}))
const challengesResponse: HackChallengesRelationship.TopLevelDocument = {
links: { self: `/hacks/${encodeURIComponent(hack.hackid)}/challenges` },
data: challenges,
included: includedChallenges,
}
reply(challengesResponse)
}
示例2: handler
export default async function handler(req: Request, reply: IReply) {
const requestDoc: ChallengeResource.TopLevelDocument = req.payload
const challenge = new ChallengeModel({
challengeid: slugify(requestDoc.data.attributes.name),
name: requestDoc.data.attributes.name,
members: [],
})
try {
await challenge.save()
} catch (err) {
if (err.code === MongoDBErrors.E11000_DUPLICATE_KEY) {
reply(Boom.conflict('Challenge already exists'))
return
}
throw err
}
const challengeResponse: ChallengeResource.TopLevelDocument = {
links: {
self: `/challenges/${encodeURIComponent(challenge.challengeid)}`,
},
data: {
type: 'challenges',
id: challenge.challengeid,
attributes: {
name: challenge.name,
},
},
}
reply(challengeResponse).code(201)
}
示例3: handler
export default async function handler(req: Request, reply: IReply) {
const { hackId: hackid } = req.params
const hack = await HackModel
.findOne({ hackid }, 'hackid name')
.exec()
if (hack === null) {
reply(Boom.notFound('Hack not found'))
return
}
const hackResponse: HackResource.TopLevelDocument = {
links: { self: `/hacks/${encodeURIComponent(hack.hackid)}` },
data: {
type: 'hacks',
id: hack.hackid,
attributes: {
name: hack.name,
},
},
}
reply(hackResponse)
}
示例4: handler
export default async function handler(req: Request, reply: IReply) {
const { challengeId: challengeid } = req.params
const challenge = await ChallengeModel
.findOne({ challengeid }, 'challengeid name')
.exec()
if (challenge === null) {
reply(Boom.notFound('Challenge not found'))
return
}
const challengeResponse: ChallengeResource.TopLevelDocument = {
links: { self: `/challenges/${encodeURIComponent(challenge.challengeid)}` },
data: {
type: 'challenges',
id: challenge.challengeid,
attributes: {
name: challenge.name,
},
},
}
reply(challengeResponse)
}
示例5: handler
export default async function handler(req: Request, reply: IReply) {
const { teamId: teamid } = req.params
const team = await TeamModel
.findOne({ teamid }, 'teamid entries')
.populate('entries', 'hackid name')
.exec()
if (team === null) {
reply(Boom.notFound('Team not found'))
return
}
const entries = team.entries.map((hack): JSONApi.ResourceIdentifierObject => ({
type: 'hacks',
id: hack.hackid,
}))
const includedHacks = team.entries.map((hack): HackResource.ResourceObject => ({
links: { self: `/hacks/${hack.hackid}` },
type: 'hacks',
id: hack.hackid,
attributes: { name: hack.name },
}))
const entriesResponse: TeamEntriesRelationship.TopLevelDocument = {
links: { self: `/teams/${encodeURIComponent(team.teamid)}/entries` },
data: entries,
included: includedHacks,
}
reply(entriesResponse)
}
示例6: handler
export default async function handler(req: Request, reply: IReply) {
const { teamId: teamid } = req.params
const team = await TeamModel
.findOne({ teamid }, 'teamid members')
.populate('members', 'userid name')
.exec()
if (team === null) {
reply(Boom.notFound('Team not found'))
return
}
const members = team.members.map((member): JSONApi.ResourceIdentifierObject => ({
type: 'users',
id: member.userid,
}))
const includedUsers = team.members.map((member): UserResource.ResourceObject => ({
links: { self: `/users/${member.userid}` },
type: 'users',
id: member.userid,
attributes: { name: member.name },
}))
const membersResponse: TeamMembersRelationship.TopLevelDocument = {
links: { self: `/teams/${encodeURIComponent(team.teamid)}/members` },
data: members,
included: includedUsers,
}
reply(membersResponse)
}
示例7: handler
export default async function handler(req: Request, reply: IReply) {
const { teamId: teamid } = req.params
const requestDoc: TeamEntriesRelationship.TopLevelDocument = req.payload
const team = await TeamModel
.findOne({ teamid }, 'teamid name entries')
.populate('entries', 'hackid')
.exec()
if (team === null) {
reply(Boom.notFound('Team not found'))
return
}
const hackIdsToAdd = requestDoc.data.map((hack) => hack.id)
const existingHackIds = hackIdsToAdd.filter((hackIdToAdd) => team.entries.some((actualhack) => actualhack.hackid === hackIdToAdd))
if (existingHackIds.length > 0) {
reply(Boom.badRequest('One or more hacks are already entries of this team'))
return
}
const hacks = await HackModel
.find({ hackid: { $in: hackIdsToAdd } }, 'hackid name')
.exec()
if (hacks.length !== hackIdsToAdd.length) {
reply(Boom.badRequest('One or more of the specified hacks could not be found'))
return
}
const hackObjectIds = hacks.map((hack) => hack._id)
const teams = await TeamModel
.find({ entries: { $in: hackObjectIds } }, 'teamid')
.exec()
if (teams.length > 0) {
reply(Boom.badRequest('One or more of the specified hacks are already in a team'))
return
}
team.entries = team.entries.concat(hacks.map((hack) => hack._id))
await team.save()
const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
hacks.forEach((hack) => {
eventBroadcaster.trigger('teams_update_entries_add', {
teamid: team.teamid,
name: team.name,
entry: {
hackid: hack.hackid,
name: hack.name,
},
}, req.logger)
})
reply()
}
示例8: handler
export default async function handler(req: Request, reply: IReply) {
const { teamId: teamid } = req.params
const requestDoc: TeamMembersRelationship.TopLevelDocument = req.payload
const team = await TeamModel
.findOne({ teamid }, 'teamid name members')
.populate('members', 'userid')
.exec()
if (team === null) {
reply(Boom.notFound('Team not found'))
return
}
const userIdsToAdd = requestDoc.data.map((user) => user.id)
const existingUserIds = userIdsToAdd.filter((userIdToAdd) => team.members.some((actualMember) => actualMember.userid === userIdToAdd))
if (existingUserIds.length > 0) {
reply(Boom.badRequest('One or more users are already members of this team'))
return
}
const users = await UserModel
.find({ userid: { $in: userIdsToAdd } }, 'userid name')
.exec()
if (users.length !== userIdsToAdd.length) {
reply(Boom.badRequest('One or more of the specified users could not be found'))
return
}
const userObjectIds = users.map((user) => user._id)
const teams = await TeamModel
.find({ members: { $in: userObjectIds } }, 'teamid')
.exec()
if (teams.length > 0) {
reply(Boom.badRequest('One or more of the specified users are already in a team'))
return
}
team.members = team.members.concat(users.map((user) => user._id))
await team.save()
const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
users.forEach((user) => {
eventBroadcaster.trigger('teams_update_members_add', {
teamid: team.teamid,
name: team.name,
member: {
userid: user.userid,
name: user.name,
},
}, req.logger)
})
reply()
}
示例9: handler
export default async function handler(request: Request, reply: IReply) {
const requestDoc: AttendeeResource.TopLevelDocument = request.payload
const attendee = new AttendeeModel({
attendeeid: requestDoc.data.id,
})
try {
await attendee.save()
} catch (err) {
if (err.code === MongoDBErrors.E11000_DUPLICATE_KEY) {
reply(Boom.conflict('Attendee already exists'))
return
}
throw err
}
const attendeeResponse: AttendeeResource.TopLevelDocument = {
links: { self: `/attendees/${encodeURIComponent(attendee.attendeeid)}` },
data: {
type: 'attendees',
id: attendee.attendeeid,
},
}
reply(attendeeResponse).code(201)
}
示例10: reply
export async function updateAccount(server: Server, request: Request, reply: IReply)
{
const id = request.params["id"];
const apiKey = request.auth.credentials.apiKey;
const accountToUpdate: Account = request.payload;
let dbAccount: Account;
// Get the original account
try
{
dbAccount = await Accounts.findByApiKey(apiKey);
// Only update the account if the ApiKey and Id match.
if (!dbAccount || dbAccount._id !== id || dbAccount.apiKey !== apiKey)
{
return reply(notFound("No account find with that id and API key combination."));
}
}
catch (e)
{
console.error("Failed to retrieve account when updating.", e);
return reply(boom(e));
}
// Transfer update props to the dbAccount
for (let prop in accountToUpdate)
{
dbAccount[prop] = accountToUpdate[prop];
}
// Never update the account's ID or apiKey
dbAccount._id = id;
dbAccount.apiKey = apiKey;
try
{
const update = await Accounts.Database.put(accountToUpdate);
if (!update.ok)
{
console.error("Failed to update account.", update);
return reply(expectationFailed("Failed to update account."));
}
dbAccount._rev = update.rev;
}
catch (e)
{
console.error("Failed to update account.", e);
return reply(boom(e));
}
return reply(dbAccount);
}