Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uu-z/koma
An advanced framework based on easy maintenance
https://github.com/uu-z/koma
koa koma nodejs
Last synced: 27 days ago
JSON representation
An advanced framework based on easy maintenance
- Host: GitHub
- URL: https://github.com/uu-z/koma
- Owner: uu-z
- Created: 2018-07-27T03:26:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-18T07:40:43.000Z (about 6 years ago)
- Last Synced: 2024-11-14T12:29:25.881Z (3 months ago)
- Topics: koa, koma, nodejs
- Language: JavaScript
- Homepage:
- Size: 596 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koma
Combind `model` `route` `controller` `services` `validators`... everything you want in just one module
## install
```
> yarn add koma
```### start
```js
const { koma } = require("koma");koma.$use({
routes: {
"get /": async ctx => (ctx.body = "Hello World")
},
start: {
config: {
PORT: 8001,
RUN: true
}
}
});
```### Graphql-compose
```js
const _ = require("lodash");
const { MongooseUtils } = require("koma/plugins/mongoose");
const { models } = MongooseUtils;
const { signJWT } = require("koma/plugins/jwt");module.exports = {
name: "User",
gql: {
resolvers: {
Mutation: {
Login: {
type: `type Login {account: Account!, jwt: String!}`,
args: { identifier: "String!", password: "String!" },
hide: true,
resolve: async ({ args }) => {
const { identifier, password } = args;
const account = await models("Account")
.findOne({ $or: [{ username: identifier }] })
.select("+password");
if (!account) throw new Error("No user founded");
const validPassword = await account.verifyPassword(password);
if (validPassword) {
delete account.password;
return { account, jwt: signJWT({ _id: account._id, role: account.role }) };
} else {
throw new Error("Invalid password or username");
}
}
},
SignUp: {
type: `type User {username: String!}`,
args: {
username: "String!",
password: "String!"
},
resolve: async ({ args }) => {
const user = await models("Account").create(args);
return user;
}
}
}
}
},
models: {
Account: {
schema: {
username: { type: "string", required: true, unique: true },
password: { type: "string", select: false, required: true, bcrypt: true, hidden: true }
},
options: {
timestamp: true
}
}
}
};
```