refactor(backend): use insert instead of save
This commit is contained in:
		
							parent
							
								
									91c56ceb6e
								
							
						
					
					
						commit
						37a4e5f4fc
					
				
					 6 changed files with 10 additions and 10 deletions
				
			
		|  | @ -46,7 +46,7 @@ export default define(meta, async (ps, user) => { | ||||||
| 	const permission = unique(ps.permission.map(v => v.replace(/^(.+)(\/|-)(read|write)$/, '$3:$1'))); | 	const permission = unique(ps.permission.map(v => v.replace(/^(.+)(\/|-)(read|write)$/, '$3:$1'))); | ||||||
| 
 | 
 | ||||||
| 	// Create account
 | 	// Create account
 | ||||||
| 	const app = await Apps.save({ | 	const app = await Apps.insert({ | ||||||
| 		id: genId(), | 		id: genId(), | ||||||
| 		createdAt: new Date(), | 		createdAt: new Date(), | ||||||
| 		userId: user ? user.id : null, | 		userId: user ? user.id : null, | ||||||
|  | @ -55,7 +55,7 @@ export default define(meta, async (ps, user) => { | ||||||
| 		permission, | 		permission, | ||||||
| 		callbackUrl: ps.callbackUrl, | 		callbackUrl: ps.callbackUrl, | ||||||
| 		secret: secret, | 		secret: secret, | ||||||
| 	}); | 	}).then(x => Apps.findOneOrFail(x.identifiers[0])); | ||||||
| 
 | 
 | ||||||
| 	return await Apps.pack(app, null, { | 	return await Apps.pack(app, null, { | ||||||
| 		detail: true, | 		detail: true, | ||||||
|  |  | ||||||
|  | @ -56,14 +56,14 @@ export default define(meta, async (ps, user) => { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	const channel = await Channels.save({ | 	const channel = await Channels.insert({ | ||||||
| 		id: genId(), | 		id: genId(), | ||||||
| 		createdAt: new Date(), | 		createdAt: new Date(), | ||||||
| 		userId: user.id, | 		userId: user.id, | ||||||
| 		name: ps.name, | 		name: ps.name, | ||||||
| 		description: ps.description || null, | 		description: ps.description || null, | ||||||
| 		bannerId: banner ? banner.id : null, | 		bannerId: banner ? banner.id : null, | ||||||
| 	} as Channel); | 	} as Channel).then(x => Channels.findOneOrFail(x.identifiers[0])); | ||||||
| 
 | 
 | ||||||
| 	return await Channels.pack(channel, user); | 	return await Channels.pack(channel, user); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -130,7 +130,7 @@ export default define(meta, async (ps, user) => { | ||||||
| 
 | 
 | ||||||
| 	const credentialIdString = credentialId.toString('hex'); | 	const credentialIdString = credentialId.toString('hex'); | ||||||
| 
 | 
 | ||||||
| 	await UserSecurityKeys.save({ | 	await UserSecurityKeys.insert({ | ||||||
| 		userId: user.id, | 		userId: user.id, | ||||||
| 		id: credentialIdString, | 		id: credentialIdString, | ||||||
| 		lastUsed: new Date(), | 		lastUsed: new Date(), | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ export default define(meta, async (ps, user) => { | ||||||
| 
 | 
 | ||||||
| 	const challengeId = genId(); | 	const challengeId = genId(); | ||||||
| 
 | 
 | ||||||
| 	await AttestationChallenges.save({ | 	await AttestationChallenges.insert({ | ||||||
| 		userId: user.id, | 		userId: user.id, | ||||||
| 		id: challengeId, | 		id: challengeId, | ||||||
| 		challenge: hash(Buffer.from(challenge, 'utf-8')).toString('hex'), | 		challenge: hash(Buffer.from(challenge, 'utf-8')).toString('hex'), | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ export default async function(follower: { id: User['id']; host: User['host']; ur | ||||||
| 	if (blocking != null) throw new Error('blocking'); | 	if (blocking != null) throw new Error('blocking'); | ||||||
| 	if (blocked != null) throw new Error('blocked'); | 	if (blocked != null) throw new Error('blocked'); | ||||||
| 
 | 
 | ||||||
| 	const followRequest = await FollowRequests.save({ | 	const followRequest = await FollowRequests.insert({ | ||||||
| 		id: genId(), | 		id: genId(), | ||||||
| 		createdAt: new Date(), | 		createdAt: new Date(), | ||||||
| 		followerId: follower.id, | 		followerId: follower.id, | ||||||
|  | @ -39,7 +39,7 @@ export default async function(follower: { id: User['id']; host: User['host']; ur | ||||||
| 		followeeHost: followee.host, | 		followeeHost: followee.host, | ||||||
| 		followeeInbox: Users.isRemoteUser(followee) ? followee.inbox : undefined, | 		followeeInbox: Users.isRemoteUser(followee) ? followee.inbox : undefined, | ||||||
| 		followeeSharedInbox: Users.isRemoteUser(followee) ? followee.sharedInbox : undefined, | 		followeeSharedInbox: Users.isRemoteUser(followee) ? followee.sharedInbox : undefined, | ||||||
| 	}); | 	}).then(x => FollowRequests.findOneOrFail(x.identifiers[0])); | ||||||
| 
 | 
 | ||||||
| 	// Publish receiveRequest event
 | 	// Publish receiveRequest event
 | ||||||
| 	if (Users.isLocalUser(followee)) { | 	if (Users.isLocalUser(followee)) { | ||||||
|  |  | ||||||
|  | @ -16,12 +16,12 @@ export async function registerOrFetchInstanceDoc(host: string): Promise<Instance | ||||||
| 	const index = await Instances.findOne({ host }); | 	const index = await Instances.findOne({ host }); | ||||||
| 
 | 
 | ||||||
| 	if (index == null) { | 	if (index == null) { | ||||||
| 		const i = await Instances.save({ | 		const i = await Instances.insert({ | ||||||
| 			id: genId(), | 			id: genId(), | ||||||
| 			host, | 			host, | ||||||
| 			caughtAt: new Date(), | 			caughtAt: new Date(), | ||||||
| 			lastCommunicatedAt: new Date(), | 			lastCommunicatedAt: new Date(), | ||||||
| 		}); | 		}).then(x => Instances.findOneOrFail(x.identifiers[0])); | ||||||
| 
 | 
 | ||||||
| 		federationChart.update(true); | 		federationChart.update(true); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue