本文整理匯總了TypeScript中typeorm.getConnection函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getConnection函數的具體用法?TypeScript getConnection怎麽用?TypeScript getConnection使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getConnection函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: editAdmin
public async editAdmin(attributes: AdminFormInterface): Promise<boolean> {
const formData = await this.checkForm(attributes, 'edit');
if (!formData) {
return false;
}
try {
const admin = await getConnection().getRepository(MoAdmins)
.findOne({
id: attributes.id
});
if (attributes.password) {
const convertedPassword = await Admins.passwordConvert(attributes.password);
admin.password = convertedPassword;
}
admin.login = attributes.login;
admin.level = attributes.level;
admin.customAccess = JSON.stringify(attributes.permissions);
await getConnection().getRepository(MoAdmins).save(admin);
} catch (error) {
console.error(error);
return false;
}
return true;
}
示例2: deleteAdmin
public async deleteAdmin(id: number): Promise<boolean> {
const admin = await this.getAdmin(id);
if (admin.id === this.user.id) {
this.message += 'You can not delete yourself';
return false;
} else if (admin.level >= this.user.level) {
this.message += 'Denied. Access level is low, you can not delete this admin';
return false;
}
try {
const label = await getConnection().getRepository(MoAdmins)
.findOne({
id: id
});
label.deleted = true;
await getConnection().getRepository(MoAdmins).save(label);
} catch (error) {
console.error(error);
return false;
}
return true;
}
示例3: editPage
public async editPage(attributes: PagesFormInterface): Promise<boolean> {
const formData = await this.checkForm(attributes);
if (!formData) {
return false;
}
try {
const page: MoPages = await getConnection().getRepository(MoPages)
.findOne({
id: attributes.id
});
page.title = attributes.title;
page.metaTitle = attributes.metaTitle;
page.metaDescription = attributes.metaDescription;
page.link = attributes.link;
page.text = attributes.text;
page.enabled = attributes.enabled;
await getConnection().getRepository(MoPages).save(page);
} catch (error) {
console.error(error);
return false;
}
return true;
}
示例4: editLabel
public async editLabel(attributes: LabelsFormInterface): Promise<boolean> {
const formData = await this.checkForm(attributes, 'edit');
if (!formData) {
return false;
}
try {
const label = await getConnection().getRepository(MoLabels)
.findOne({
id: attributes.id
});
label.name = attributes.name;
label.output = attributes.output;
await getConnection().getRepository(MoLabels).save(label);
} catch (error) {
console.error(error);
return false;
}
return true;
}
示例5: cleanAuth
static async cleanAuth(user: MoAdmins): Promise<boolean> {
const response = await getConnection().getRepository(MoUsersAuth)
.find({
user: user
});
if (response) {
await getConnection().getRepository(MoUsersAuth).remove(response);
}
return true;
}
示例6: addAdmin
public async addAdmin(attributes: AdminFormInterface): Promise<boolean> {
const formData = await this.checkForm(attributes, 'add');
if (!formData) {
return false;
}
const convertedPassword = await Admins.passwordConvert(attributes.password);
const newAdmin = new MoAdmins();
newAdmin.login = attributes.login;
newAdmin.password = convertedPassword;
newAdmin.level = attributes.level;
newAdmin.customAccess = JSON.stringify(attributes.permissions);
try {
await getConnection().getRepository(MoAdmins).save(newAdmin);
} catch (error) {
console.error(error);
return false;
}
return true;
}
示例7: getLabels
public async getLabels(attributes: GetLabelInterface): Promise<Array<LabelsFormInterface>> {
const returnLabels = [];
try {
// Fetching previous attempts to login
const labels = await getConnection().getRepository(MoLabels)
.find({
where: {
siteId: attributes.siteId,
deleted: false
},
order: {
name: 'ASC'
}
});
for (const label of labels) {
returnLabels.push({
id: label.id,
name: label.name,
output: this.stripLabel(label.output)
});
}
} catch (error) {
console.error(error);
}
return returnLabels;
}
示例8: createAndSaveTransaction
async createAndSaveTransaction(transactionData: any, status: string, blockData?: any ): Promise<void> {
const txRepo = getConnection().getMongoRepository(Transaction);
const type = this.getTxTypeByData(transactionData);
const { from, to, jcrAmount } = this.getFromToJcrAmountByTxDataAndType(transactionData, type);
let timestamp;
let blockNumber;
if (blockData) {
timestamp = blockData.timestamp;
blockNumber = blockData.number;
} else {
timestamp = Math.round(+new Date() / 1000);
}
const transformedTxData = {
transactionHash: transactionData.hash,
from,
type,
to,
ethAmount: this.web3.utils.fromWei(transactionData.value).toString(),
jcrAmount: jcrAmount,
status,
timestamp,
blockNumber
};
const txToSave = txRepo.create(transformedTxData);
await txRepo.save(txToSave);
}
示例9: getPages
public async getPages(attributes: GetPageInterface): Promise<Array<PagesFormInterface>> {
const returnPages = [];
try {
// Fetching previous attempts to login
const pages: Array<MoPages> = await getConnection().getRepository(MoPages)
.find({
where: {
siteId: attributes.siteId,
deleted: false
},
order: {
title: 'ASC'
}
});
for (const page of pages) {
returnPages.push({
id: page.id,
title: page.title,
metaTitle: page.metaTitle,
metaDescription: page.metaDescription,
link: page.link,
text: page.text,
enabled: page.enabled
});
}
} catch (error) {
console.error(error);
}
return returnPages;
}
示例10: getLabel
public async getLabel(attributes: GetLabelInterface): Promise<LabelsFormInterface> {
let returnLabel = null;
try {
// Fetching previous attempts to login
const label = await getConnection().getRepository(MoLabels)
.findOne({
siteId: attributes.siteId,
deleted: false,
id: attributes.id
});
if (label) {
returnLabel = {
id: label.id,
name: label.name,
output: label.output
};
}
} catch (error) {
console.error(error);
}
return returnLabel;
}