本文整理汇总了TypeScript中frost-component.MongoProvider.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MongoProvider.create方法的具体用法?TypeScript MongoProvider.create怎么用?TypeScript MongoProvider.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frost-component.MongoProvider
的用法示例。
在下文中一共展示了MongoProvider.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: create
async create(screenName: string, password: string | null, name: string, description: string, options?: IUserCreateOptions): Promise<UserDocument> {
options = options || { };
if (!options.root && password == null) {
throw new Error('password is empty');
}
let passwordHash = null;
if (password != null) {
const salt = randomRange(1, 99999);
const hash = buildHash(`${password}.${salt}`);
passwordHash = `${hash}.${salt}`;
}
const source: IUserDocumentSoruce = {
screenName,
passwordHash,
name,
description
};
if (options.root) {
source.root = true;
}
const rawDocument: IUserDocument = await this.db.create('api.users', source);
return new UserDocument(rawDocument);
}
示例2: async
menu.add('initialize (register root app and root user)', () => true, async (ctx) => {
if (dataFormatState != DataFormatState.needInitialization) {
const allowClear = await q('(!) are you sure you want to REMOVE ALL COLLECTIONS and ALL DOCUMENTS in target database? (y/n) > ');
if (!allowClear) {
return;
}
const clean = async (collection: string) => {
await db.remove(collection, {});
log(`cleaned ${collection} collection.`);
};
await clean('meta');
await clean('api.apps');
await clean('api.tokens');
await clean('api.users');
await clean('api.userRelations');
await clean('api.postings');
await clean('api.storageFiles');
}
let appName = await read('app name(default: Frost Web) > ');
if (appName == '') appName = 'Frost Web';
const userDoc = await userService.create('frost', null, 'Frost公式', 'オープンソースSNS Frostです。', { root: true });
log('root user created.');
await appService.create(appName, userDoc, userDoc.description, AuthScopes.toArray().map(s => s.id), { root: true });
log('root app created.');
await db.create('meta', { type: 'dataFormat', value: currentDataVersion });
await refreshMenu();
});
示例3: createChatPosting
async createChatPosting(userId: string | ObjectId, text: string, attachmentIds?: (ObjectId | string)[]): Promise<ChatPostingDocument> {
const source: IChatPostingDocumentSoruce = {
type: 'chat',
userId: MongoProvider.buildId(userId),
text
};
if (attachmentIds) {
source.attachmentIds = attachmentIds.map(i => MongoProvider.buildId(i));
}
const documentRaw: IChatPostingDocument = await this.db.create('api.postings', source);
return new ChatPostingDocument(documentRaw);
}
示例4: create
async create(app: IAppDocument, user: IUserDocument, scopes: string[], host?: boolean): Promise<TokenDocument> {
const data: ITokenDocumentSource = {
appId: app._id,
userId: user._id,
scopes: scopes,
accessToken: uid(128)
};
if (host) {
data.host = true;
}
const tokenDocRaw: ITokenDocument = await this.db.create('api.tokens', data);
return new TokenDocument(tokenDocRaw);
}
示例5: create
async create(name: string, user: UserDocument, description: string, scopes: string[], options?: IAppCreateOptions): Promise<AppDocument> {
options = options || { };
const source: IAppDocumentSoruce = {
creatorId: user._id,
description: description,
name: name,
scopes: scopes
};
if (options.root) {
source.root = true;
}
const appDocRaw: IAppDocument = await this.db.create('api.apps', source);
return new AppDocument(appDocRaw);
}