User schema wip
This commit is contained in:
parent
8b8b145360
commit
633e552b31
3 changed files with 135 additions and 2 deletions
106
imports/api/Users/Users.js
Normal file
106
imports/api/Users/Users.js
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
/* eslint-disable consistent-return */
|
||||||
|
/* eslint-disable import/no-absolute-path */
|
||||||
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import { defaultCreatedAt, defaultUpdateAt } from '/imports/api/Utility/Utils.js';
|
||||||
|
import i18n from 'i18next';
|
||||||
|
|
||||||
|
const schemaUserProfile = new SimpleSchema({
|
||||||
|
name: { type: String, optional: true },
|
||||||
|
lang: { type: String, optional: true },
|
||||||
|
telegramChatId: { type: Number, optional: true },
|
||||||
|
telegramUsername: { type: String, optional: true },
|
||||||
|
telegramFirstName: { type: String, optional: true },
|
||||||
|
telegramLanguageCode: { type: String, optional: true },
|
||||||
|
createdAt: defaultCreatedAt,
|
||||||
|
updatedAt: defaultUpdateAt
|
||||||
|
});
|
||||||
|
|
||||||
|
const schemaUser = new SimpleSchema({
|
||||||
|
username: {
|
||||||
|
type: String,
|
||||||
|
// i18nLabel: 'Usuario/a',
|
||||||
|
regEx: /^[a-z0-9A-Z_]{3,15}$/,
|
||||||
|
// For accounts-password, either emails or username is required,
|
||||||
|
// but not both.
|
||||||
|
// It is OK to make this optional here because the accounts-password
|
||||||
|
// package
|
||||||
|
// does its own validation.
|
||||||
|
// Third-party login packages may not require either.
|
||||||
|
// Adjust this schema as necessary for your usage.
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
emails: {
|
||||||
|
type: Array,
|
||||||
|
min: 1,
|
||||||
|
label() { return i18n.t('Lista de emails de contacto'); },
|
||||||
|
// For accounts-password, either emails or username is required,
|
||||||
|
// but not both.
|
||||||
|
// It is OK to make this optional here because the accounts-password
|
||||||
|
// package
|
||||||
|
// does its own validation.
|
||||||
|
// Third-party login packages may not require either.
|
||||||
|
// Adjust this schema as necessary for your usage.
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
'emails.$': {
|
||||||
|
label: false,
|
||||||
|
type: Object
|
||||||
|
},
|
||||||
|
'emails.$.address': {
|
||||||
|
type: String,
|
||||||
|
label: '',
|
||||||
|
regEx: SimpleSchema.RegEx.Email
|
||||||
|
},
|
||||||
|
'emails.$.verified': {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true // if not present === notVerified
|
||||||
|
},
|
||||||
|
profile: {
|
||||||
|
type: schemaUserProfile,
|
||||||
|
// i18nLabel: 'Otros datos',
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
// Make sure this services field is in your schema
|
||||||
|
// if you're using any of the accounts packages
|
||||||
|
services: {
|
||||||
|
type: Object,
|
||||||
|
optional: true,
|
||||||
|
// autoform: { type: 'hidden' },
|
||||||
|
blackbox: true
|
||||||
|
},
|
||||||
|
// Add `roles` to your schema if you use the meteor-roles package.
|
||||||
|
// Option 1: Object type
|
||||||
|
// If you specify that type as Object, you must also specify the
|
||||||
|
// `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
|
||||||
|
// Example:
|
||||||
|
// Roles.addUsersToRoles(userId, ['admin'], Roles.GLOBAL_GROUP);
|
||||||
|
// You can't mix and match adding with and without a group since
|
||||||
|
// you will fail validation in some cases.
|
||||||
|
// roles: {
|
||||||
|
// type: Object,
|
||||||
|
// optional: true,
|
||||||
|
// autoform: { type: 'hidden' },
|
||||||
|
// blackbox: true
|
||||||
|
// }
|
||||||
|
// Option 2: [String] type
|
||||||
|
// If you are sure you will never need to use role groups, then
|
||||||
|
// you can specify [String] as the type
|
||||||
|
roles: {
|
||||||
|
type: Array,
|
||||||
|
// autoform: { type: 'hidden' },
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
// https://github.com/todda00/meteor-friendly-slugs/issues/1
|
||||||
|
friendlySlugs: {
|
||||||
|
type: Object,
|
||||||
|
optional: true,
|
||||||
|
blackbox: true
|
||||||
|
},
|
||||||
|
slug: {
|
||||||
|
type: String,
|
||||||
|
optional: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Meteor.users.attachSchema(schemaUser);
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
// import '../Users';
|
||||||
|
|
||||||
Meteor.publish('users.editProfile', function usersProfile() {
|
Meteor.publish('users.editProfile', function usersProfile() {
|
||||||
return Meteor.users.find(this.userId, {
|
return Meteor.users.find(this.userId, {
|
||||||
fields: {
|
fields: {
|
||||||
emails: 1,
|
emails: 1,
|
||||||
profile: 1,
|
profile: 1,
|
||||||
services: 1,
|
services: 1
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
26
imports/api/Utility/Utils.js
Normal file
26
imports/api/Utility/Utils.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* eslint-disable consistent-return */
|
||||||
|
|
||||||
|
export const defaultCreatedAt = {
|
||||||
|
type: Date,
|
||||||
|
// autoform: { type: 'hidden' },
|
||||||
|
autoValue: () => {
|
||||||
|
if (this.isInsert) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
// Prevent user from supplying their own value
|
||||||
|
this.unset();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultUpdateAt = {
|
||||||
|
type: Date,
|
||||||
|
// autoform: { type: 'hidden' },
|
||||||
|
autoValue: () => {
|
||||||
|
if (this.isUpdate || this.isInsert) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Commented because we want to have updateAt = createAt initialy
|
||||||
|
// denyInsert: true,
|
||||||
|
optional: true
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue