1.0.81 • Published 3 months ago

wapplr-posttypes v1.0.81

Weekly downloads
23
License
MIT
Repository
github
Last release
3 months ago

Wapplr-posttypes

With this package easier initialize a database collection for Wapplr.

//server.js
import wapplrPostTypes from "wapplr-posttypes";
import wapplrServer from "wapplr";
const wapp = wapplrServer({config: {
        server: {
            database: {
                mongoConnectionString: "mongodb://localhost/wapplr",
            }
        },
        globals: {
            WAPP: "yourBuildHash",
            ROOT: __dirname
        }
    }
});

wapplrPostTypes({wapp});

const titlePattern = /^.{1,250}$/;
const contentPattern = /^.{1,2500}$/;
const contentBriefPattern = /^.{1,500}$/;

const post = await wapp.server.postTypes.getPostType({
    name: "post",
    addIfThereIsNot: true,
    config: {

        mongoConnectionString: "mongodb://localhost/wapplr",
        
        modelName: "Post",
        schemaFields: {
            title: {
                type: String,
                wapplr: {
                    pattern: titlePattern,
                    required: true
                }
            },
            subtitle: {
                type: String,
                wapplr: {
                    pattern: titlePattern,
                }
            },
            content: {
                type: String,
                wapplr: {
                    pattern: contentPattern,
                    required: true
                }
            },
            contentBrief: {
                type: String,
                wapplr: {
                    pattern: contentBriefPattern,
                }
            },
        },
        setSchemaMiddleware: function({schema}){},
        
        statuses: {
            featured: 120,
            approved: 100,
            requiredData: 50,
            created: 40,
            deleted: 30,
            banned: 20
        },
        statusField: "_status",
        requiredDataForStatus: {
            title: { type: String },
            content: { type: String },
        },
        
        messages: {
            savePostDefaultFail: "Sorry, there was an issue save the entry, please try again",
            invalidData: "Invalid data",
            missingData: "Missing data",
            lowStatusLevel: "Your status level is too low to perform the operation",
            postNotFound: "Post not found",
            accessDenied: "You do not have permission to perform that operation"
        },

        resolvers: {
            getAll: function ({Model}) {
                return {
                    extendResolver: "findMany",
                    args: null,
                    resolve: async function({input}) {
                        return await Model.find();
                    }
                }
            },
        }
    }
})

wapp.server.listen();
//client.js
/*...*/
const send = wapp.requests.send;
const response = await send({requestName:"postGetAll"});
const posts = response.postGetAll;

License

MIT

1.0.81

3 months ago

1.0.80

4 months ago

1.0.73

7 months ago

1.0.77

7 months ago

1.0.76

7 months ago

1.0.75

7 months ago

1.0.74

7 months ago

1.0.79

6 months ago

1.0.78

7 months ago

1.0.62

9 months ago

1.0.61

10 months ago

1.0.60

10 months ago

1.0.66

8 months ago

1.0.65

8 months ago

1.0.64

8 months ago

1.0.63

8 months ago

1.0.69

8 months ago

1.0.68

8 months ago

1.0.67

8 months ago

1.0.72

7 months ago

1.0.71

7 months ago

1.0.70

7 months ago

1.0.59

10 months ago

1.0.51

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.44

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.47

2 years ago

1.0.45

2 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.40

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.29

3 years ago

1.0.30

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.28

3 years ago

1.0.24

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.23

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago