-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mailing list backend utilities #1
Changes from all commits
f281f35
0341274
db98f61
bbb6b7d
f00be53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,140 @@ module.mailing-list | |
=================== | ||
|
||
Mykoop module responsible to manage mailing lists | ||
|
||
|
||
#Documentation | ||
|
||
##Endpoints | ||
- `GET /json/mailinglist` | ||
- See [GetMailingLists](#getmailinglist) | ||
- `POST /json/mailinglist` | ||
- See [AddMailingLists](#addmailinglist) | ||
- `PUT /json/mailinglist/:id` | ||
- See [UpdateMailingLists](#updatemailinglist) | ||
- `DELETE /json/mailinglist/:id` | ||
- See [DeleteMailingLists](#deletemailinglist) | ||
- `POST /json/mailinglist/:id/register` | ||
- See [RegisterToMailingList](#registertomailinglist) | ||
|
||
##Available Methods | ||
###AddMailingList | ||
```ts | ||
addMailingList( | ||
params: { | ||
name: string; | ||
description?: string; | ||
}, | ||
callback: (err?, result?: {id: number}) => void | ||
); | ||
``` | ||
- params: | ||
- name: name of the mailing list | ||
- description: description of the mailing list | ||
- callback: callback once the treatment is done | ||
- err: Error or null | ||
- result: | ||
- id: id of the newly created mailing list | ||
- Possible errors: | ||
- app.name : `string;` | ||
- `"duplicate"`: name of the mailing already exists | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. list |
||
- validation.name: `string[];` | ||
- `"empty"`: name is empty | ||
- `"tooShort__#__"`: name is too short, # is the minimal length | ||
- `"tooLong__#__"`: name is too long, # is the maximal length | ||
|
||
###UpdateMailingList | ||
```ts | ||
updateMailingList( | ||
params: { | ||
id: number; | ||
name: string; | ||
description?: string; | ||
}, | ||
callback: (err?) => void | ||
) | ||
``` | ||
- params: | ||
- id: id of the mailing list | ||
- name: name of the mailing list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new name |
||
- description: description of the mailing list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new description |
||
- callback: callback once the treatment is done | ||
- err: Error or null | ||
- Possible errors: | ||
- app.name : `string;` | ||
- `"duplicate"`: name of the mailing already exists | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. list |
||
- app.id: `string;` | ||
- `"invalid"`: id is invalid | ||
- validation.id: `string[];` | ||
- `"notAnInteger"`: id is not an integer | ||
- `"NaN"`: id is not a number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be possible to only have |
||
- validation.name: `string[];` | ||
- `"empty"`: name is empty | ||
- `"tooShort__#__"`: name is too short, # is the minimal length | ||
- `"tooLong__#__"`: name is too long, # is the maximal length | ||
|
||
###DeleteMailingList | ||
```ts | ||
deleteMailingList( | ||
params: { | ||
id: number; | ||
}, | ||
callback: (err?) => void | ||
); | ||
``` | ||
- params: | ||
- id: id of the mailing list to delete | ||
- callback: callback once the treatment is done | ||
- err: Error or null | ||
- Possible errors: | ||
- app.id: `string;` | ||
- `"invalid"`: id is invalid | ||
- validation.id: `string[];` | ||
- `"empty"`: mailing list id is missing | ||
- `"notAnInteger"`: mailing list id is not an integer | ||
- `"NaN"`: mailing list id is not a number | ||
|
||
###GetMailingList | ||
```ts | ||
getMailingLists( | ||
params: {}, | ||
callback: (err?, result?: {id: number; name: string; description: string;}[]) => void | ||
) | ||
``` | ||
- params: empty | ||
- callback: callback once the treatment is done | ||
- err: Error or null | ||
- result: list of mailing lists | ||
- id: id of the mailing list | ||
- name: name of the mailing list | ||
- description: description of the mailing list | ||
|
||
###RegisterToMailingList | ||
```ts | ||
registerToMailingList( | ||
params: { | ||
idUser: number; | ||
idMailingList: number; | ||
}, | ||
callback: (err?) => void | ||
) | ||
``` | ||
- params: | ||
- idUser: id of the user that wants to register to the mailing list | ||
- idMailingList: id of the mailing list to register to | ||
- callback: callback once the treatment is done | ||
- err: Error or null | ||
- Possible errors: | ||
- app.idUser: `string;` | ||
- `"invalid"`: user id is invalid | ||
- `"alreadyRegistered"`: user is already registered to the mailing list | ||
- app.idMailingList: `string;` | ||
- `"invalid"`: mailing list id is invalid | ||
- validation.id: `string[];` | ||
- `"empty"`: mailing list id is missing | ||
- `"notAnInteger"`: mailing list id is not an integer | ||
- `"NaN"`: mailing list id is not a number | ||
- validation.idUser: `string[];` | ||
- `"empty"`: user id is missing | ||
- `"notAnInteger"`: user id is not an integer | ||
- `"NaN"`: user id is not a number |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,49 @@ | ||
var endpoints = require("../../metadata/endpoints"); | ||
var validation = require("../validation/index"); | ||
// Controllers. | ||
function attachControllers(binder) { | ||
binder.attach({ | ||
endPoint: endpoints.mailinglist.add, | ||
validation: validation.mailingListDefinition | ||
}, binder.makeSimpleController("addMailingList", function (req) { | ||
var params = { | ||
name: req.param("name"), | ||
description: req.param("description") | ||
}; | ||
return params; | ||
})); | ||
binder.attach({ | ||
endPoint: endpoints.mailinglist.update, | ||
validation: validation.mailingListDefinition | ||
}, binder.makeSimpleController("updateMailingList", function (req) { | ||
var params = { | ||
id: parseInt(req.param("id")), | ||
name: req.param("name"), | ||
description: req.param("description") | ||
}; | ||
return params; | ||
})); | ||
binder.attach({ | ||
endPoint: endpoints.mailinglist.delete, | ||
validation: validation.mailinglistId | ||
}, binder.makeSimpleController("deleteMailingList", function (req) { | ||
var params = { | ||
id: parseInt(req.param("id")) | ||
}; | ||
return params; | ||
})); | ||
binder.attach({ | ||
endPoint: endpoints.mailinglist.list | ||
}, binder.makeSimpleController("getMailingLists")); | ||
binder.attach({ | ||
endPoint: endpoints.mailinglist.register, | ||
validation: validation.mailinglistIdPlusUserId | ||
}, binder.makeSimpleController("registerToMailingList", function (req) { | ||
var params = { | ||
idMailingList: parseInt(req.param("id")), | ||
idUser: parseInt(req.param("idUser")) | ||
}; | ||
return params; | ||
})); | ||
} | ||
exports.attachControllers = attachControllers; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,74 @@ | ||
import Express = require("express"); | ||
import endpoints = require("../../metadata/endpoints"); | ||
import utils = require("mykoop-utils"); | ||
|
||
import validation = require("../validation/index"); | ||
|
||
// Controllers. | ||
|
||
export function attachControllers(binder) { | ||
export function attachControllers( | ||
binder: utils.ModuleControllersBinder<mkmailinglist.Module> | ||
) { | ||
binder.attach( | ||
{ | ||
endPoint: endpoints.mailinglist.add, | ||
validation: validation.mailingListDefinition | ||
}, | ||
binder.makeSimpleController("addMailingList", function (req: Express.Request) { | ||
var params: MailingList.AddMailingList.Params = { | ||
name: req.param("name"), | ||
description: req.param("description") | ||
}; | ||
return params; | ||
}) | ||
); | ||
|
||
binder.attach( | ||
{ | ||
endPoint: endpoints.mailinglist.update, | ||
validation: validation.mailingListDefinition | ||
}, | ||
binder.makeSimpleController("updateMailingList", function (req: Express.Request) { | ||
var params: MailingList.UpdateMailingList.Params = { | ||
id: parseInt(req.param("id")), | ||
name: req.param("name"), | ||
description: req.param("description") | ||
}; | ||
return params; | ||
}) | ||
); | ||
|
||
binder.attach( | ||
{ | ||
endPoint: endpoints.mailinglist.delete, | ||
validation: validation.mailinglistId | ||
}, | ||
binder.makeSimpleController("deleteMailingList", function (req: Express.Request) { | ||
var params: MailingList.DeleteMailingList.Params = { | ||
id: parseInt(req.param("id")) | ||
}; | ||
return params; | ||
}) | ||
); | ||
|
||
binder.attach( | ||
{ | ||
endPoint: endpoints.mailinglist.list | ||
}, | ||
binder.makeSimpleController("getMailingLists") | ||
); | ||
|
||
binder.attach( | ||
{ | ||
endPoint: endpoints.mailinglist.register, | ||
validation: validation.mailinglistIdPlusUserId | ||
}, | ||
binder.makeSimpleController("registerToMailingList", function (req: Express.Request) { | ||
var params: MailingList.RegisterToMailingList.Params = { | ||
idMailingList: parseInt(req.param("id")), | ||
idUser: parseInt(req.param("idUser")) | ||
}; | ||
return params; | ||
}) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's because you want to easily copy-paste it into Postman, but do we really want to expose the
/json
prefix here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either we expose it completely or we don't. I think it's nice to know what are the endpoints since there can be more or less than the methods