Files
habitica/website/server/models/userNotification.js
Kevin Smith c5d9ee1e0a Implemented new Achievement and Badge: Joined a Challenge (Fixes #8613) (#8761)
* Added image

* Added new achievement to user schema

* Added new achievement to content

* Added new achievement to libs

* Added achievement text to locale

* Added achievement to notification model and controller

* Grant achievement on joining or creating first challenge

* Added achievement to modal template

* Compiled new sprites

* Added integration tests

* Fix linting error
2017-06-07 09:43:16 -07:00

52 lines
1.3 KiB
JavaScript

import mongoose from 'mongoose';
import baseModel from '../libs/baseModel';
import { v4 as uuid } from 'uuid';
import validator from 'validator';
const NOTIFICATION_TYPES = [
'DROPS_ENABLED',
'REBIRTH_ENABLED',
'WON_CHALLENGE',
'STREAK_ACHIEVEMENT',
'ULTIMATE_GEAR_ACHIEVEMENT',
'REBIRTH_ACHIEVEMENT',
'NEW_CONTRIBUTOR_LEVEL',
'CRON',
'GROUP_TASK_APPROVAL',
'GROUP_TASK_APPROVED',
'LOGIN_INCENTIVE',
'GROUP_INVITE_ACCEPTED',
'SCORED_TASK',
'BOSS_DAMAGE', // Not used currently but kept to avoid validation errors
'GUILD_PROMPT',
'GUILD_JOINED_ACHIEVEMENT',
'CHALLENGE_JOINED_ACHIEVEMENT',
];
const Schema = mongoose.Schema;
export let schema = new Schema({
id: {
type: String,
default: uuid,
validate: [validator.isUUID, 'Invalid uuid.'],
required: true,
},
type: {type: String, required: true, enum: NOTIFICATION_TYPES},
data: {type: Schema.Types.Mixed, default: () => {
return {};
}},
}, {
strict: true,
minimize: false, // So empty objects are returned
_id: false, // use id instead of _id
});
schema.plugin(baseModel, {
noSet: ['_id', 'id'],
// timestamps: true, // Temporarily removed to debug a possible bug
_id: false, // use id instead of _id
});
export let model = mongoose.model('UserNotification', schema);