-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Harsh Raj
committed
Jan 26, 2024
1 parent
dd958c4
commit 80903c6
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// comments-model.ts - A mongoose model | ||
// | ||
// See http://mongoosejs.com/docs/models.html | ||
// for more of what you can do here. | ||
import { Application } from '../declarations'; | ||
import { Model, Mongoose } from 'mongoose'; | ||
|
||
export default function (app: Application): Model<any> { | ||
const modelName = 'comments'; | ||
const mongooseClient: Mongoose = app.get('mongooseClient'); | ||
const { Schema } = mongooseClient; | ||
const schema = new Schema({ | ||
text: { type: String, required: true } | ||
}, { | ||
timestamps: true | ||
}); | ||
|
||
// This is necessary to avoid model compilation errors in watch mode | ||
// see https://mongoosejs.com/docs/api/connection.html#connection_Connection-deleteModel | ||
if (mongooseClient.modelNames().includes(modelName)) { | ||
(mongooseClient as any).deleteModel(modelName); | ||
} | ||
return mongooseClient.model<any>(modelName, schema); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Service, MongooseServiceOptions } from 'feathers-mongoose'; | ||
import { Application } from '../../declarations'; | ||
|
||
export class Comments extends Service { | ||
//eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
constructor(options: Partial<MongooseServiceOptions>, app: Application) { | ||
super(options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { HooksObject } from '@feathersjs/feathers'; | ||
import * as authentication from '@feathersjs/authentication'; | ||
// Don't remove this comment. It's needed to format import lines nicely. | ||
|
||
const { authenticate } = authentication.hooks; | ||
|
||
export default { | ||
before: { | ||
all: [ authenticate('jwt') ], | ||
find: [], | ||
get: [], | ||
create: [], | ||
update: [], | ||
patch: [], | ||
remove: [] | ||
}, | ||
|
||
after: { | ||
all: [], | ||
find: [], | ||
get: [], | ||
create: [], | ||
update: [], | ||
patch: [], | ||
remove: [] | ||
}, | ||
|
||
error: { | ||
all: [], | ||
find: [], | ||
get: [], | ||
create: [], | ||
update: [], | ||
patch: [], | ||
remove: [] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Initializes the `comments` service on path `/comments` | ||
import { ServiceAddons } from '@feathersjs/feathers'; | ||
import { Application } from '../../declarations'; | ||
import { Comments } from './comments.class'; | ||
import createModel from '../../models/comments.model'; | ||
import hooks from './comments.hooks'; | ||
|
||
// Add this service to the service type index | ||
declare module '../../declarations' { | ||
interface ServiceTypes { | ||
'comments': Comments & ServiceAddons<any>; | ||
} | ||
} | ||
|
||
export default function (app: Application): void { | ||
const options = { | ||
Model: createModel(app), | ||
paginate: app.get('paginate') | ||
}; | ||
|
||
// Initialize our service with any options it requires | ||
app.use('/comments', new Comments(options, app)); | ||
|
||
// Get our initialized service so that we can register hooks | ||
const service = app.service('comments'); | ||
|
||
service.hooks(hooks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import app from '../../src/app'; | ||
|
||
describe('\'comments\' service', () => { | ||
it('registered the service', () => { | ||
const service = app.service('comments'); | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |