1.0.81 • Published 1 year ago

wapplr-posttypes v1.0.81

Weekly downloads
23
License
MIT
Repository
github
Last release
1 year 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

1 year ago

1.0.80

1 year ago

1.0.73

2 years ago

1.0.77

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.79

2 years ago

1.0.78

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.69

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.59

2 years ago

1.0.51

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.58

3 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.44

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.47

4 years ago

1.0.45

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.40

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.29

4 years ago

1.0.30

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.28

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.23

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago