Skip to content

Commit

Permalink
Revert to all lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijos committed Sep 26, 2023
1 parent a7c1556 commit 8910b7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/controllers/tickets.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Response, Request } from "express";
import Ticket from "../models/Ticket";
import Ticket from "../models/ticket";
import type ErrorResponse from "../models/ErrorResponse.model";

const tickets = {
getTickets: async function getTickets(req: Request, res: Response): Promise<object | ErrorResponse> {
getTickets: async function getTickets(
req: Request,
res: Response
): Promise<object | ErrorResponse> {
try {
const allTickets = await Ticket.aggregate([
{ $sort: { _id: -1 } },
{ $project: { id: "$_id", code: 1, trainnumber: 1, traindate: 1, _id: 0 } }
]);

return res.json({
data: allTickets
});
Expand All @@ -18,18 +21,21 @@ const tickets = {
errors: {
status: 500,
source: "/tickets",
title: 'Database Error',
title: "Database Error",
message: err.message
}
});
}
},

createTicket: async function createTicket(req: Request, res: Response): Promise<object | ErrorResponse> {
createTicket: async function createTicket(
req: Request,
res: Response
): Promise<object | ErrorResponse> {
const newTicket = new Ticket(req.body);
try {
await newTicket.save()

try {
await newTicket.save();

return res.status(201).json({
data: {
Expand All @@ -42,11 +48,11 @@ const tickets = {
errors: {
status: 500,
source: "/tickets",
title: 'Database Error',
title: "Database Error",
message: err.message
}
});
}
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/models/ticket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, model } from 'mongoose';
import { Schema, model } from "mongoose";

interface ITicket {
code: string;
Expand All @@ -12,6 +12,6 @@ const ticketSchema = new Schema<ITicket>({
traindate: { type: String, required: true }
});

const Ticket = model<ITicket>('Ticket', ticketSchema);
const Ticket = model<ITicket>("Ticket", ticketSchema);

export default Ticket;

0 comments on commit 8910b7c

Please sign in to comment.