fmt
This commit is contained in:
parent
3be98d0e20
commit
0d2e8dfe36
|
@ -1,4 +1,4 @@
|
|||
version: '3'
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
mongodb:
|
||||
|
|
|
@ -23,7 +23,11 @@ class ImageController {
|
|||
} catch (error: any) {
|
||||
if (error instanceof mongo.MongoServerError && error.code === 11000) {
|
||||
// Should return 409 Conflict for existing urls
|
||||
res.status(409).json({ error: `the image with URL ${error.keyValue.url} already exists` });
|
||||
res
|
||||
.status(409)
|
||||
.json({
|
||||
error: `the image with URL ${error.keyValue.url} already exists`,
|
||||
});
|
||||
} else if (error instanceof mongoose.Error.ValidationError) {
|
||||
// Should return 400 Bad request for invalid requests
|
||||
res.status(400).json({ error: error.message });
|
||||
|
|
|
@ -15,8 +15,7 @@ app.get("/", (_, res) => {
|
|||
|
||||
app.get("/images", imageController.getAllImages);
|
||||
app.post("/images", authControler.authorize, imageController.addImage);
|
||||
app.post("/login", authControler.login)
|
||||
|
||||
app.post("/login", authControler.login);
|
||||
|
||||
const start = async () => {
|
||||
// Set the default port to 8080, or use the PORT environment variable
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import mongoose, { Document } from "mongoose";
|
||||
|
||||
export interface Auth extends Document {
|
||||
app: String,
|
||||
secret: String
|
||||
app: String;
|
||||
secret: String;
|
||||
}
|
||||
|
||||
const AuthSchema = new mongoose.Schema({
|
||||
|
|
|
@ -9,18 +9,18 @@ export interface Image extends Document {
|
|||
const ImageSchema = new mongoose.Schema({
|
||||
url: {
|
||||
type: String,
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
enum: {
|
||||
values: ["consumed", "unavailable", "available"],
|
||||
},
|
||||
required: true
|
||||
required: true,
|
||||
},
|
||||
tags: {
|
||||
type: [String]
|
||||
}
|
||||
type: [String],
|
||||
},
|
||||
});
|
||||
|
||||
export default mongoose.model<Image>('images', ImageSchema);
|
||||
export default mongoose.model<Image>("images", ImageSchema);
|
||||
|
|
|
@ -41,7 +41,6 @@ describe("GET /images works properly", async () => {
|
|||
});
|
||||
|
||||
describe("POST /images works properly", () => {
|
||||
|
||||
it("should return 401 for unauthenticated requests", async () => {
|
||||
const res = await request(app)
|
||||
.post("/images")
|
||||
|
|
|
@ -19,4 +19,3 @@ describe("/login", async () => {
|
|||
expect(res.status).toBe(403);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue